Bubble Query Tutorial
#include <stdio.h>intMain () {Doublearr[]={9,6,1,7,8,3,0,4,5,2};inti,j;printf ("\n************ before queuing *************\n"); for(i=0;i<Ten; i++){if(I! =9) printf ("%d,", Arr[i]);Elseprintf ("%d", Arr[i]);} for(i=8; i>=0; i--)//control the maximum subscript for each trip comparison{ for(j=0; j<=i;j++)//control subscript for each adjacent element comparison{if(arr[j]>arr[j+1])//When the previous number is larger than the number that follows{DoubleTemp//define temporary Variable tempTEMP=ARR[J];//Assign the previous number to temparr[j]=arr[j+1];//reverse position of the number of front and reararr[j+1]=temp;//put the larger number in the back}}}printf ("\n************ sort of *************\n"); for(i=0;i<Ten; i++){if(I! =9) printf ("%d,", Arr[i]);Elseprintf ("%d", Arr[i]);}return 0; }
Output results
9 6 1 7 8 3 0,452// pre-sort output 012 3 4 5 6 7 8 9 // output results after sorting
This is I read the C tutorial after the simulation write a piece of programming, I hope to help you!
C-language bubbling query tutorial