Abdulg

Bubblesort (C)

Aug 7th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. void PrintIntArray(int Array[2048])
  4. {
  5.     int Iterator;
  6.  
  7.     for (Iterator = 0; Array[Iterator] != 2146; Iterator++)
  8.     {
  9.         printf("%d,",Array[Iterator]);
  10.     }
  11.  
  12.     printf("\n\n");
  13. }
  14.  
  15. int main()
  16. {
  17.     int Input[2048];
  18.     int Increment;
  19.     int Done = 0;
  20.  
  21.     printf("Please input numbers. Insert 2146 when done.\n");
  22.  
  23.     for (Increment = 0; Done == 0; Increment++)
  24.     {  
  25.         scanf("%d",&Input[Increment]);
  26.         if(Input[Increment] == 2146) Done = 1;
  27.     }
  28.  
  29.     int Iterator, Temp = 0, Passes = 0;
  30.     Increment -= 2;
  31.  
  32.     while (Done == 1)
  33.     {
  34.         Done = 0;
  35.  
  36.         for (Iterator = 0; Iterator < Increment; Iterator++)
  37.         {
  38.             if (Input[Iterator + 1] < Input[Iterator])
  39.             {
  40.                 Temp = Input[Iterator + 1];
  41.                 Input[Iterator + 1] = Input[Iterator];
  42.                 Input[Iterator] = Temp;
  43.                 Done = 1;
  44.             }
  45.         }
  46.  
  47.         Passes++;
  48.         printf("Pass %d:\n", Passes);
  49.         PrintIntArray(Input);  
  50.     }
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment