int[] numbers = new int[10];
Console.WriteLine("Please enter 10 unique numbers for sorting:");
for (int i = 0; i < numbers.Length; i++)
Console.Write("Enter number " + (i + 1) + ": ");
if (int.TryParse(Console.ReadLine(), out numbers[i]))
for (int j = 0; j < i; j++)
if (numbers[j] == numbers[i])
Console.WriteLine("Number must be unique. Try again.");
Console.WriteLine("Invalid input. Please enter a valid integer.");
Console.WriteLine("Choose a sorting method:\n1. Bubble Sort\n2. Shell Sort\n3. Selection Sort\n4. Insertion Sort");
Console.Write("Enter your choice (1-4): ");
int choice = Convert.ToInt32(Console.ReadLine());
new BubbleSort().Sort(numbers);
new ShellSort().Sort(numbers);
new SelectionSort().Sort(numbers);
new InsertionSort().Sort(numbers);
Console.WriteLine("Invalid choice. Exiting program.");
Console.WriteLine("Sorted numbers:");
foreach (int num in numbers)
static void SaveToFile(int[] array)
string filePath = "sorted_numbers.txt";
using (StreamWriter sw = new StreamWriter(filePath))
foreach (int num in array)
Console.WriteLine("Numbers have been saved to " + filePath);
Console.WriteLine("An error occurred: " + ex.Message);
public void Sort(int[] array)
for (int i = 0; i < array.Length - 1; i++)
for (int j = 0; j < array.Length - i - 1; j++)
if (array[j] > array[j + 1])
public void Sort(int[] array)
for (int gap = n / 2; gap > 0; gap /= 2)
for (int i = gap; i < n; i++)
for (j = i; j >= gap && array[j - gap] > temp; j -= gap)
array[j] = array[j - gap];
public void Sort(int[] array)
for (int i = 0; i < array.Length - 1; i++)
for (int j = i + 1; j < array.Length; j++)
if (array[j] < array[minIndex])
int temp = array[minIndex];
array[minIndex] = array[i];
public void Sort(int[] array)
for (int i = 1; i < array.Length; i++)
while (j >= 0 && array[j] > key)