Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void DoBubbleSort(int[]arraytosort) {
- int endingpoint = 1,
- temp;
- bool issorted;
- int swaps = 0,
- iterations = 0,
- passes = 0; //debug
- do {
- issorted = true;
- for(int i = arraytosort.Length - 1; i >= endingpoint; i--)
- {
- iterations++; //debug
- //Console.WriteLine("i: " + i + " i-1: " + (i - 1));
- if (arraytosort[i - 1] > arraytosort[i])
- {
- swaps++; //debug
- //swap the numbers around
- temp = arraytosort[i - 1];
- arraytosort[i - 1] = arraytosort[i];
- arraytosort[i] = temp;
- issorted = false;
- }
- }
- Console.Write("pass: " + passes + " ");
- printarray(arraytosort); //debug
- Console.WriteLine();
- passes++; //debug
- endingpoint++;
- } while (!issorted);
- Console.WriteLine("Sorting Complete!");
- Console.WriteLine("Statistics\n----------");
- Console.WriteLine("Passes: " + passes + ", Iterations: " + iterations + " Swaps: " + swaps);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement