#if 0 #include<bits/stdc++.h> usingnamespacestd; int head; structNode { int key; int next; }; structQueueNode { int front,rear; };
voiddistribute(Node r[],int n,QueueNode q[],int m) { int i = 0; //默认为0 最后的next为 -1 while(1) { int key = r[i].key; if(q[key].front==-1) { q[key].front = i; } else { r[q[key].rear].next = i; } q[key].rear = i; i = r[i].next; if(i == -1) break; } }
voidcollection(Node r[],int n,QueueNode q[],int m) { int k = 0; while(q[k].front==-1) k++; int first = q[k].front; int last = q[k].rear; head = first; while(k<m) { k++; if(q[k].front!=-1) { r[last].next = q[k].front; last = q[k].rear; } } r[last].next = -1; }