[Html] int data [10] = };
// The input element is:
Array to be sorted by data
Start subscript of the array to be sorted
The subscript of the first element of the unordered sequence to be sorted by the end.
The length of the array.
Start = 0; end = 1 at the beginning, because only 0 is ordered, and subscript 1 is the first element in the nine unordered objects.
Call method: insertationSort (data, 10 );
Through continuous Recursion
The second call to insertationSort (data, 10 );
The third call to insertationSort (data, 10 );
.
.
.
Until insertationSort (data, 0, 9, 10 );
For example
Void insertationSort (int * data, int start, int end, int length)
{
If (end <= length)
{
Int index = end;
Int temp = 0;
// Locate the position to which the last element should be inserted. If yes, exit the loop.
For (int I = start; I <end; I ++ ){
If (data [end] <data [I]) {
Index = I;
Temp = data [end];
Break;
}
}
// If a specified position is found, the specified position element starts to move the unit backward. Otherwise, the Unit remains unchanged.
If (index! = End ){
Data [index] = temp;
For (int I = end-1; I> = index; I --){
Data [I + 1] = data [I];
}
}
End ++;
InsertationSort (data, start, end, length );
}
}
Int data [10] = };
// The input element is:
Array to be sorted by data
Start subscript of the array to be sorted
The subscript of the first element of the unordered sequence to be sorted by the end.
The length of the array.
Start = 0; end = 1 at the beginning, because only 0 is ordered, and subscript 1 is the first element in the nine unordered objects.
Call method: insertationSort (data, 10 );
Through continuous Recursion
The second call to insertationSort (data, 10 );
The third call to insertationSort (data, 10 );
.
.
.
Until insertationSort (data, 0, 9, 10 );
For example
Void insertationSort (int * data, int start, int end, int length)
{
If (end <= length)
{
Int index = end;
Int temp = 0;
// Locate the position to which the last element should be inserted. If yes, exit the loop.
For (int I = start; I <end; I ++ ){
If (data [end] <data [I]) {
Index = I;
Temp = data [end];
Break;
}
}
// If a specified position is found, the specified position element starts to move the unit backward. Otherwise, the Unit remains unchanged.
If (index! = End ){
Data [index] = temp;
For (int I = end-1; I> = index; I --){
Data [I + 1] = data [I];
}
}
End ++;
InsertationSort (data, start, end, length );
}
}