There is an integer linked list. The table element's key value is an integer of no more than three digits. A Indicates the hundred bits of the key value, B indicates the ten bits, and C indicates the single bits. First, the single-digit C in the key value splits and links the linked list. First, the linked list is split into up to 10 queue linked lists, then, the chain lists of the ten queues after the split are re-collected into a chain list in the order of 0 to 9 in the C value. Then, perform the same split and link operations on the key values B and A, and the linked list is sorted from small to large. If a linked list is followed by their key values and their table meta links are:
35,298,832,932, 38,635, 48,118,128,138,148,158
// Binsort. cpp: defines the entry point for the console application.
//
# Include "stdafx. H"
# Include <stdio. h>
# Include <stdlib. h>
# Define keyn 3
Int inputnumber [] = {35,298,832,932, 38,635, 48,118,128,138,148,158 };
# Define n sizeof inputnumber/sizeof inputnumber [0]
Struct Element
{
Int key;
Struct element * next;
};
Void basesort (struct element ** H)
{
Int I, j, factor = 1;
Struct element * linklist [10], * tailoflinklist [10], * P, * U;
For (I = 0, P = * h; I <keyn; factor * = 10, I ++)
{
For (j = 0; j <10; j ++)
{
Linklist [J] = NULL;
}
While (P)
{
U = p-> next;
J = (p-> key/factor) % 10;
If (linklist [J] = NULL)
{
Linklist [J] = P;
}
Else
{
Tailoflinklist [J]-> next = P;
}
Tailoflinklist [J] = P;
P-> next = NULL;
P = u;
}
P = NULL;
For (j = 0; j <10; j ++)
{
If (linklist [J] = NULL)
{
Continue;
}
If (P = NULL)
{
P = linklist [J];
}
Else
{
U-> next = linklist [J];
}
U = tailoflinklist [J];
}
}
* H = P;
}
Void main ()
{
Struct element * H, * U;
Int I;
H = NULL;
For (I = 0; I <n; I ++)
{
U = (struct element *) malloc (sizeof (struct element ));
U-> key = inputnumber [I];
U-> next = h;
H = u;
}
Basesort (& H );
For (u = H; U; u = u-> next)
{
Printf ("% 4D", U-> key );
}
Scanf ("");
}