Advertisement
Semior001

sort

Nov 23rd, 2016
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. void sort(){
  2.     int temp;
  3.     bool sorted = false;
  4.     while(!sorted){
  5.         for(int i = 0; i < n-1; i++){
  6.             if(sum[i] > sum[i+1]){
  7.                 sorted = false;
  8.                 temp = sum[i];
  9.                 sum[i] = sum[i+1];
  10.                 sum[i+1] = temp;
  11.             }
  12.         }
  13.         sorted = true;
  14.     }
  15. }
  16.  
  17. void reverse(){
  18.     int temp;
  19.     bool sorted = false;
  20.     while(!sorted){
  21.         for(int i = 0; i < n-1; i++){
  22.             if(sum[i] < sum[i+1]){
  23.                 sorted = false;
  24.                 temp = sum[i];
  25.                 sum[i] = sum[i+1];
  26.                 sum[i+1] = temp;
  27.             }
  28.         }
  29.         sorted = true;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement