1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#if 0 #include<bits/stdc++.h> using namespace std; int head; struct Node { int key; int next; }; struct QueueNode { int front,rear; };
void distribute(Node r[],int n,QueueNode q[],int m) { int i = 0; 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; } }
void collection(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; }
void bucketSort(Node r[],int n,QueueNode q[],int m) { for(int i=0; i<n; i++) r[i].next = i+1; r[n-1].next = -1;
for(int i=0; i<m; i++) { q[i].front = q[i].rear = -1; } distribute(r,n,q,m); collection(r,n,q,m); }
int main() { Node r[1000]; QueueNode q[1000]; int n; cin>>n; for(int i=0; i<n; i++) r[i].key = n-i; bucketSort(r,n,q,100); while(head!=-1) { cout<<r[head].key<<" "; head = r[head].next; } } #endif
|
近期评论