Function to sort the elements of each bucket
| 98 | |
| 99 | // Function to sort the elements of each bucket |
| 100 | struct Node *InsertionSort(struct Node *list) |
| 101 | { |
| 102 | struct Node *k, *nodeList; |
| 103 | if (list == 0 || list->next == 0) |
| 104 | { |
| 105 | return list; |
| 106 | } |
| 107 | |
| 108 | nodeList = list; |
| 109 | k = list->next; |
| 110 | nodeList->next = 0; |
| 111 | while (k != 0) { |
| 112 | struct Node *ptr; |
| 113 | if (nodeList->data > k->data) |
| 114 | { |
| 115 | struct Node *tmp; |
| 116 | tmp = k; |
| 117 | k = k->next; |
| 118 | tmp->next = nodeList; |
| 119 | nodeList = tmp; |
| 120 | continue; |
| 121 | } |
| 122 | |
| 123 | for (ptr = nodeList; ptr->next != 0; ptr = ptr->next) |
| 124 | { |
| 125 | if (ptr->next->data > k->data) |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | if (ptr->next != 0) |
| 130 | { |
| 131 | struct Node *tmp; |
| 132 | tmp = k; |
| 133 | k = k->next; |
| 134 | tmp->next = ptr->next; |
| 135 | ptr->next = tmp; |
| 136 | continue; |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | ptr->next = k; |
| 141 | k = k->next; |
| 142 | ptr->next->next = 0; |
| 143 | continue; |
| 144 | } |
| 145 | } |
| 146 | return nodeList; |
| 147 | } |
| 148 | |
| 149 | int getBucketIndex(int value) |
| 150 | { |