In my previous blog, I made a bubble sort of three different lists, distinguishing types with single linked lists and two-way lists, with leading nodes and not leading nodes. In fact, the overall idea is the same, respectively, to (n-1) time to traverse the list, compare the size of the two nodes before and after the exchange. In order to learn the integrity of this blog, we will be able to achieve the lead node in the bidirectional non cyclic chain table bubble sort. Code uploaded to Https://github.com/chenyufeng1991/DoubleLinkedList_NodeList_BubbleSort.
The core code is as follows:
Bubble sort
void Bubblesort (Node *phead,node *ptail) {
int count = Sizelist (Phead, ptail);
Node *pmove;
Pmove = phead->next;
while (Count > 1) {while
(Pmove->next!= ptail) {
if (Pmove->element > Pmove->next->element) { c7/>//Exchange
int temp;
temp = pmove->element;
Pmove->element = pmove->next->element;
pmove->next->element = temp;
}
Pmove = pmove->next;
}
Pmove = phead->next;
Count--;
}
printf ("%s function execution, list bubbling sort complete \ n", __function__);
}