Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int a[10]; int n=9;
- a[0]=9; a[1]=15; a[2]=13; a[3]=11; a[4]=5; a[5]=3; a[6]=1; a[7]=20; a[8]=2;
- int j,ultim,sus,jos;
- int temp;
- sus= 1; jos= n-1; ultim= n-1;
- do {
- for( j= jos; j >= sus; j --)
- if (a[j-1]>a[j])
- {
- temp= a[j-1]; a[j-1]= a[j]; a[j]= temp;
- ultim= j;
- } /*FOR*/
- sus= ultim+1;
- for( j=sus; j <= jos; j ++)
- if (a[j-1]>a[j])
- {
- temp=a[j-1]; a[j-1]=a[j]; a[j]=temp;
- ultim=j;
- } /*FOR*/
- jos=ultim-1;
- for(int k=0; k < n ;k++){
- printf("%d ",a[k]);
- if(n-1==k)
- printf("\n");
- }
- } while (!(sus>jos));
- for(int k=0; k < n ;k++){
- printf("%d ",a[k]);
- if(n-1==k)
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement