amitsp21

Untitled

Dec 19th, 2018
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. void bubbleSort(list<int> arr) {
  2.    int i;
  3.    int j;
  4.    int tmp;
  5.    for (i = 0; i < #arr-1; i++) {    
  6.        for (j = 0; j < #arr-i-1; j++) {
  7.            if (arr[j] > arr[j+1]) {
  8.               tmp = arr[j];
  9.               arr[j] = arr[j+1];
  10.               arr[j+1] = tmp;
  11.            }
  12.        }
  13.     }
  14. }
  15.  
  16. int main() {
  17.     list<int> a;
  18.     int i;
  19.     a = [10, 2, 15, 8, 20, 13, 9];
  20.     bubbleSort(a);
  21.     for(i = 0; i < #a; ++i) {
  22.         printi(a[i]);
  23.     }
  24.     return 0;
  25. }
Add Comment
Please, Sign In to add comment