Machine test guidelines

1. Bubble Sort

 1 #include <stdio.h>
 2 int main(){
 3     int i,j,n,temp;
 4     int a[100];
 5     while(scanf("%d",&n)!=EOF){
 6         for(int i=0;i<n;i++){
 7             scanf("%d",&a[i]);
 8         }
 9     for(i=0;i<n-1;i++){
10         for(j=0;j<n-i-1;j++){
11             if(a[j]>a[j+1]){
12                 temp = a[j];
13                 a[j]=a[j+1];
14                 a[j+1] = temp;
15             }
16         }
17     }
18     for(i=0;i<n;i++){
19         printf("%d ",a[i]);
20     }
21     printf("\n");
22 }
23 return 0;
24 }
View Code

Guess you like

Origin www.cnblogs.com/dolphin-bamboo/p/12114873.html
Recommended