Advertisement
AntonioVillanueva

BubleSort Circuit Cellar

Aug 3rd, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. //BubleSort
  2.  
  3. //#include <stdio>
  4. #include <cstdio>
  5. //Declaration of Functions
  6. void bubble_sort(long[],const long);
  7.  
  8. //Test Driver
  9. int main()
  10. {
  11.     long array[100],n;
  12.     printf ("Enter number elements up to 100\n");
  13.     //scanf_s("%ld",&n);
  14.     scanf("%ld",&n);
  15.     printf ("Enter %ld integers\n",n);
  16.    
  17.     for (long c=0;c<n;c++)
  18.     //scanf_s("%ld",&array[c]);
  19.     scanf("%ld",&array[c]);
  20.     bubble_sort(array,n);
  21.    
  22.     printf ("Sorted list in ascending order:\n");
  23.     for (long c=0;c<n;c++)
  24.         printf ("%ld\n",array[c]);
  25.        
  26.     return 0;
  27. }
  28.  
  29. void bubble_sort(long list[],const long n)
  30. {
  31.     long c=0;
  32.     long d=0;
  33.    
  34.     for (c=0;c<(n-1);c++)
  35.     {
  36.         for (d=0;d<(n-c-1);d++)
  37.         {
  38.             if (list[d] >list[d+1])
  39.             {
  40.                 /*Swapping*/
  41.                
  42.                 const long t=list[d];
  43.                 list [d]=list[d+1];
  44.                 list[d+1]=t;
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement