Sequencing is an important operation in computer programming, and its function is to rearrange any sequence of data elements (or records) into an ordered sequence of keywords.
What we've known before is probably bubble sort, select sort, but in contrast, these two methods are not very efficient, in this article I briefly introduce the direct insertion of the sort.
The direct insertion sort is a simple sort method that inserts a record into an ordered table that is sorted so that a new one is obtained. An ordered table with an additional number of records.
For example, the initial arrangement of a set of records to be sorted looks like this:
R ((), R (), R (), R (), R (), R (27) ...
Suppose that during the sort process, the first 4 records are rearranged in the order in which they are incremented by keyword, form an ordered sequence of 4 records: {R (), R (), R (), R (97)} first insert the fifth record of the initial sequence above into this recorded record, You first look in a good sequence to determine where R (76) should be inserted, and then insert.
void Dir_sort (SqList L)
{
int i, J;
for (i = 2; i < l.length i++)
{
if (LT (L.r[i].data, L.r[i-1].data))
{
l.r[0] = l.r[i];
L.r[i] = l.r[i-1];
for (j = i-2; LT (L.r[0].data, l.r[j].data); j--)
{
l.r[j+1] = l.r[j];
}
L.R[J+1] = l.r[0];
}
for (i = 1;i <= l.length; i++)
printf ("%d", l.r[i].data);
printf ("\ n");
}
This article is from the "Late Evening" blog, please be sure to keep this source http://yiluohuanghun.blog.51cto.com/3407300/879937