### 7.10 利用链表和映射表进行排序 II

void table_sort(element list[], int n, int table[])
{
// 重排 list[0], ..., list[n-1] 对应于 list[table[0]] ,..., list[table[n-1]]
int i, current, next;
element temp;
for (i = 0; i < n-1; i++)
if (table[i] != i) {
temp = list[i];
current = i;
do {
next = table[current];
list[current] = list[next];
table[current] = current;
current = next;
} while (table[current] != i);
list[current] = temp;
table[current] = current;
}
}


$R$ $R_0$ $R_1$ $R_2$ $R_3$ $R_4$ $R_5$ $R_6$ $R_7$
key 35 14 12 42 26 50 31 18
table [0] [1] [2] [3] [4] [5] [6] [7]
value 2 1 7 4 6 0 3 5

$R$ $R_0$ $R_1$ $R_2$ $R_3$ $R_4$ $R_5$ $R_6$ $R_7$
key 12 14 18 42 26 35 31 50
table [0] [1] [2] [3] [4] [5] [6] [7]
value 0 1 2 4 6 5 3 7

$R$ $R_0$ $R_1$ $R_2$ $R_3$ $R_4$ $R_5$ $R_6$ $R_7$
key 12 14 18 26 31 35 42 50
table [0] [1] [2] [3] [4] [5] [6] [7]
value 0 1 2 3 4 5 6 7