meissner61

Bubble sort with function reference

Jun 1st, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void printList(int list[10])
  6. {
  7.     for(int i=0; i<10; i++)
  8.     {
  9.         cout<<list[i]<<", ";
  10.     }
  11. }
  12.  
  13. void sort(int (&list)[10])
  14. {
  15.     int temp = 0;
  16.  
  17.     for(int i=0; i<10; i++)
  18.     {
  19.         for(int j=0; j<9; j++)
  20.         {
  21.             if(list[j]>list[j+1])
  22.             {
  23.                 temp = list[j+1];
  24.                 list[j+1] = list[j];
  25.                 list[j] = temp;
  26.             }
  27.         }
  28.     }
  29. }
  30.  
  31. int main()
  32. {
  33.     int list[10] = { 5,3,2,1,6,4,9,7,8,10 };
  34.     //int temp=99;
  35.  
  36.     cout<<"Original List:\n\n\t";
  37.  
  38.     printList(list);
  39.     cin.ignore();
  40.  
  41.     sort(list);
  42.  
  43.     cout<<"Sorted List:\n\n\t";
  44.  
  45.     printList(list);
  46.     cin.ignore();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment