Home > Back-end >  Modify the error makes the program function of bubbling use flag flag bit to reduce cycle times
Modify the error makes the program function of bubbling use flag flag bit to reduce cycle times

Time:05-13

# include
# include
using namespace std;
Const int N=6;
Void bubble_sort (int unsorted [], int n)//sorting
{
Int flag=0, m=0;
For (int I=0; i {
For (int j=0; j {
flag=0;
If (unsorted [j] & gt; Unsorted [m + 1])
{
Int temp=unsorted [j + 1);
Unsorted [j + 1)=unsorted [j];
Unsorted [j]=temp;
flag=1;
m++;
}
}
if(! Flag) break;
}
cout<" The actual "& lt; cout<" Increase the flag flags can reduce "& lt; }
Void the display (int x [], int n)
{
For (int I=0; i cout}
Int main ()
{
Int x [N];
for(int i=0; ICin> X [I];
cout<" Sort the data before: "& lt; Display (x, N);
coutBubble_sort (x, N);
cout<" After sorting sequence: "& lt; Display (x, N);
coutreturn 0;
}
The flag at work?
 [code=c] [code]=c  
[code=c] [/code] [/code] [/code]
  • Related