MCPcopy Create free account
hub / github.com/Lakhankumawat/LearnCPP / InsertionSort

Function InsertionSort

S-SortingAlgorithms/BucketSort.cpp:100–147  ·  view source on GitHub ↗

Function to sort the elements of each bucket

Source from the content-addressed store, hash-verified

98
99// Function to sort the elements of each bucket
100struct 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
149int getBucketIndex(int value)
150{

Callers 1

BucketSortFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected