I am aware that there is a sort function available in C# to sort arrays into the correct order, but for reasons, I need to do it with my own code.
I have come up with this, and some of the numbers move, but it never fully sorts. Has anyone any idea why?
static void Main(string[] args)
{
int[] arraySort = { 2, 5, 7, 3, 6, 3 };
int save;
bool sorted = false;
while(sorted == false) {
for (int i = 0; i < (arraySort.Length - 1); i++)
{
sorted = true;
if (arraySort[i] > arraySort[i + 1])
{
save = arraySort[i];
arraySort[i] = arraySort[i + 1];
arraySort[i + 1] = save;
sorted = false;
}
}
}
for (int i = 0; i < arraySort.Length; i++)
{
Console.WriteLine(arraySort[i]);
}
}
My output ends up being:
2 3 5 3 6 7