I am in front of two blog "single linked list (not the lead node) to achieve bubble sort" "single linked list to achieve bubble sort (lead node)" in detail described in the use of the lead node and not the lead node of the single linked table to achieve bubble sort, let's have a rational understanding of the single linked list and bubble sort. Today we're going to use a non-circular doubly linked list without the lead node to do the bubble sort, which is much simpler and more efficient in the process than the previous two. Code uploaded to Https://github.com/chenyufeng1991/DoubleLinkedList_BubbleSort.
The core code is as follows:
Bubble sort
Node *bubblesort (node *pnode) {
int count = sizelist (pnode);
Node *pmove;
Pmove = Pnode;
Traversal count is count-1 while
(Count > 1) {while
(Pmove->next!= NULL) {
if (Pmove->element > Pmove->n ext->element) {
int temp;
Here the data exchange is simpler than the single link table
temp = pmove->element;
Pmove->element = pmove->next->element;
pmove->next->element = temp;
}
Pmove = pmove->next;
}
count--;
Back to the head of the list again
pmove = Pnode;
}
printf ("%s function execution, bubble sort complete \ n", __function__);
return pnode;
}