Home > Back-end >  Of new insertion sort, can't find where there is a problem..
Of new insertion sort, can't find where there is a problem..

Time:10-20

#include
Int main ()
{
,4,9,5,0,2 int a [6]={10};
Int I, j, m, temp;
for(i=1; i<6; I++)
{
M=a, [I].
For (j=I - 1; J>=0; J -)
{
If (a [j] & gt; M)
{
Temp=a, [I].
A [I]=a, [j].
A [j]=temp;
}
}
}
for(i=0; i<6; I++)
{
Printf (" % d ", a [I]);
}
return 0;
}

CodePudding user response:

Exchange before using a [j] and a [I] is not correct, if you want to move the 3 to 6, 7, 637 for the first time, the second time than is 6 and 7, logic is a little problem

CodePudding user response:

You have a logical problem so your method is wrong!
Below is the sorting code I wrote for reference ~
#include
Int main ()
{
,4,9,5,0,2 int a [6]={10};
Int I, j, temp.
for(i=0; i<6; I++)
{
for(j=i+1; J<6; J++)
If (a [I] & gt; A [j])
{
Temp=a, [I].
A [I]=a, [j].
A [j]=temp;
}
}
for(i=0; i<6; I++)
Printf (" % d ", a [I]);
return 0;
}

CodePudding user response:

refer to the second floor and 蘤 old crepe reply:
before the exchange with a [j] and a [I] is not correct, if you want to move the 3 to 6, 7, 637 for the first time, than for the second time is 6 and 7, something is wrong with the logic

Ok, thank you very much (o ^ ^ o)

CodePudding user response:

reference a____jun reply: 3/f
you have a logical problem so your method is wrong!
Below is the sorting code I wrote for reference ~
#include
Int main ()
{
,4,9,5,0,2 int a [6]={10};
Int I, j, temp.
for(i=0; i<6; I++)
{
for(j=i+1; J<6; J++)
If (a [I] & gt; A [j])
{
Temp=a, [I].
A [I]=a, [j].
A [j]=temp;
}
}
for(i=0; i<6; I++)
Printf (" % d ", a [I]);
return 0;
}

It's no wonder that, thank you
  • Related