Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void bubble(int a[],int l){
- for(int i=0;i<l-1;i++){
- for(int j=0;j<l-i-1;j++){
- if(a[j]>a[j+1]){
- swap(&a[j],&a[j+1]);
- }
- }
- printf("%d pass:\n",i+1);
- printarr(a,l);
- printf("\n");
- }
- }
- void selection(int a[],int n){
- for(int i=0;i<n-1;i++){
- int m=i;
- for(int j=i+1;j<n;j++){
- if(a[j]<a[m]){
- m=j;
- }
- }
- swap(&a[m],&a[i]);
- printf("%d pass: \n",i+1);
- printarr(a,n);
- }
- }
- void insertion(int a[],int n){
- int temp,j;
- for(int i=1;i<n;i++){
- temp=a[i];
- j=i-1;
- while(j>=0 && temp<=a[j]){
- a[j+1]=a[j];
- j-=1;
- }
- a[j+1]=temp;
- printf("%d pass:\n",i);
- printarr(a,n);
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement