Home > Back-end >  C who help me
C who help me

Time:10-01



By the foaming method (bubble sort) sequence of n integers and output the result after the smallest,

The first line contains a positive integer greater than zero and less than 200 n, said there are n integers need to be sorted, the second line with n integers separated by a space,

Output from small to large, sorting result after every integer output a space,

Please note that the end of each line output line,

CodePudding user response:

 
# include & lt; Iostream>
using namespace std;


Void arr_sort (int * p, int n);
Void arr_input (int * p, int n);
Void arr_print (int * p, int n);

Int main ()
{
Const int N=200;
Int n, arr [n]={0};
cin> n;

Arr_input (arr, n);
Arr_sort (arr, n);
Arr_print (arr, n);

getchar();
return 0;
}

Void arr_sort (int * p, int n)
{
Int I, j, TMP=0;
for (i=0; I{
For (j=0; J{
If (p [j] & gt; P [m + 1])
{
TMP=p [j + 1);
P=p [m + 1] [j];
P=TMP [j];
}
}
}
}

Void arr_print (int * p, int n)
{
int i;
for (i=0; I{
Cout & lt;

}
Cout & lt; }

Void arr_input (int * p, int n)
{
int i;
for (i=0; I{
cin> P [I];
}
}

CodePudding user response:

Bubble sort is one of the most simple stable order, if you don't understand, the back of the insert select hill wait more don't, read more,
  • Related