Search Results

Search found 1 results on 1 pages for 'arianule'.

Page 1/1 | 1 

  • bubble sort logic error

    - by Arianule
    I was trying a basic sorting exercise and I was hoping I could receive some help with what is probably a basic logic error. int[] numbers = new int[] { 2, 5, 11, 38, 24, 6, 9, 0, 83, 7 }; for (int loop = 0; loop < numbers.Length; loop++) { Console.WriteLine(numbers[loop]); } Console.WriteLine("Performing a bubble sort"); bool flag = false; do { for (int loop = 0; loop < numbers.Length - 1; loop++) { if (numbers[loop] > numbers[loop + 1]) { int temporary = numbers[loop]; numbers[loop] = numbers[loop + 1]; numbers[loop + 1] = temporary; flag = true; } } } while (flag == false); for (int loop = 0; loop < numbers.Length; loop++) { Console.WriteLine(numbers[loop]); } kind regards arianule

    Read the article

1