Using methods to make a program that allows you to choose different search/sort methods. For the bubble sort, when i try and output the arrays in the bottom of the code, It prints 'System.Int32[]'. Also, The code never actually ends, it just prints out 'System.Int32[]' and 'End of pass _ '. How do i stop this from happening? Thanks
i have tried swapping {0} for the actual variable names, and changing the values of 'b < _' in the for loop.
int pass_count = 0;
bool sorted = false;
int[] changing_array = new int[5];
int[] final_array = new int[5];
int[] starting_array = new int[5];
for (int a = 0; a < 5; a++)
{
Console.WriteLine("Input number {0}", (a + 1));
changing_array[a] = Convert.ToInt32(Console.ReadLine());
}
Array.Copy(changing_array, final_array, 5);
Array.Copy(changing_array, starting_array, 5);
Array.Sort(final_array);
while (sorted == false)
{
for (int b = 0; b < 4; b++)
{
int c = b++;
int temp;
if (changing_array[b] > changing_array[c])
{
temp = changing_array[b];
changing_array[b] = changing_array[c];
changing_array[c] = temp;
}
else
{
continue;
}
}
pass_count++;
if (changing_array == final_array)
{
Console.WriteLine("It took {0} passes to sort \n{1} \ninto \n{2} ",pass_count,starting_array,final_array);
sorted = true;
}
else
{
Console.WriteLine("End of pass {0}. \n{1} \nis now \n{2} ",pass_count,starting_array,changing_array);
}
}
Assuming the numbers are "65,34,23,87,30" at the end i would like it to print "It took {0} passes to sort \n'65,34,23,87,30' \ninto \n'23,30,34,65,87' ", however it just prints 'System.Int32[]' and 'End of pass _ '.