Advertisement
starbeamrainbowlabs

Reverse Bubble Sort [Function Only w/out debug statements]

Nov 1st, 2014
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static void DoBubbleSort(int[]arraytosort) {
  2.     int endingpoint = 1,
  3.         temp;
  4.     bool issorted;
  5.    
  6.     do {
  7.         issorted = true;
  8.  
  9.         for(int i = arraytosort.Length - 1; i >= endingpoint; i--)
  10.         {
  11.            
  12.             if (arraytosort[i - 1] > arraytosort[i])
  13.             {
  14.                 //swap the numbers around
  15.                 temp = arraytosort[i - 1];
  16.                 arraytosort[i - 1] = arraytosort[i];
  17.                 arraytosort[i] = temp;
  18.  
  19.                 issorted = false;
  20.             }
  21.         }
  22.        
  23.         endingpoint++;
  24.     } while (!issorted);
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement