SHARE
TWEET

bubble sort

Sachin_biswas1418 Jul 22nd, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. int DATA[8]={32,51,27,85,66,23,13,57};
  5. int N=8;
  6. void BUBBLE(void);
  7. void main()
  8. {
  9.     int i;
  10.     printf("Values contained in DATA[8]=");
  11.     for(i=0;i<8;i++)
  12.         printf(" %d",DATA[i]);
  13.     BUBBLE();
  14.     printf("\n\nValues contained in DATA[8] after sorting =");
  15.     for(i=0;i<8;i++)
  16.         printf(" %d",DATA[i]);
  17.     getch();
  18. }
  19. void BUBBLE(void)
  20. {
  21.     int K,PTR,TEMP;
  22.     for(K=0;K<=(N-1-1);K++)
  23.     {
  24.         PTR=0;
  25.         while(PTR<=(N-K-1-1))
  26.         {
  27.             if(DATA[PTR]>DATA[PTR+1])
  28.             {
  29.                 TEMP=DATA[PTR];
  30.                 DATA[PTR]=DATA[PTR+1];
  31.                 DATA[PTR+1]=TEMP;
  32.             }
  33.             PTR=PTR+1;
  34.         }
  35.     }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top