Home > Back-end >  Bother comments this code, if in the middle of the circle and the while loop not understand ~
Bother comments this code, if in the middle of the circle and the while loop not understand ~

Time:09-15

Void listbyname ()
{
int i,j,k;
Struct person t;
For (I=1; i {
If (STRCMP (per [I] cName, per [I - 1]. CName) & lt; 0)
{
T=per [I];
J=I - 1;
Do
{
Per [j + 1)=per [j];
J -;
}
While ((STRCMP (tc Name, per [j]. Journal of cName) & lt; 0 & & J & gt;=0));
Per [m + 1]=t;
}
}
Printf (" \ n \ t sort success! Whether show?" );
Printf (" \ n \ t1. Yes 2. No ");
Printf (" please enter a number you choose: ");
The scanf (" % d ", & amp; K);
If (1==k)
Showall ();
return;
}

CodePudding user response:

While in the bubbling
T=per [I];//record the current to the bubbling of element

Per [j + 1)=per [j];//to the bubbling elements meet the conditions of the while (smaller than the previous element) put forward the element

J -;//forward loop is

While ((STRCMP (tc Name, per [j]. Journal of cName) & lt; 0 & & J & gt;=0));//to be bubbling elements and the front element is



CodePudding user response:

This should be insertion sort, the while loop is looking for the position of the insertion, per [j + 1)=per [j]; This operation is found in the empty rooms, to the position of the insert,
  • Related