Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Пейстбин
- #include <stdio.h>
- #define SIZE 10
- //sort array: compare two neighboring elements, starts with 0el first time, and
- //smallest end up at 0-place, starts with 1st el second time-sm to 1st place...
- //bubble
- int main()
- {
- int flag,temp,i,j,k,arr[SIZE]={3,2,4,1,5,6,7,8,9,10};//{9,5,7,3,2,6,8,4,1,0};
- for(i=0;i<SIZE;i++)printf("%d\t",arr[i]);//print array
- for(i=0;i<SIZE;i++)//place to put max number
- {printf("\ni=%d\n",i);flag=0;//place=SIZE-i;
- for(j=0;j<SIZE;j++)
- {printf("j=%d\t",j);
- if(arr[j]>arr[j+1])
- temp=arr[j],arr[j]=arr[j+1],arr[j+1]=temp,flag++;
- }//for j
- if(!flag)
- printf("\n%d lines\n",i),i=SIZE;//skip the rest!!!
- printf("\n");
- for(k=0;k<SIZE;k++)printf("%d\t",arr[k]);//print array'
- printf("\n");
- if(i==SIZE-2)i=SIZE;
- }//for i
- for(i=0;i<SIZE;i++)printf("%d\t",arr[i]);//print array
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement