In my previous blog, "single linked list (not the lead node) to achieve bubble sort" to achieve the not the lead node of the single list of bubble sort, breaking the common use of the array to bubble the convention. Then the leading node of the linked list is more commonly used. This blog we are going to implement the lead node of the single linked list bubble sort. It is important to note whether the lead node is critical for handling the first nodes. Code uploaded to: Https://github.com/chenyufeng1991/BubbleSortLinkedList_HeadNode.
The core code is as follows:
Node *bubblesort (node *pnode) {
int count = sizelist (pnode);//To control the number of
node *pmove;
Pmove = pnode->next;
Traversal count is count-1 while
(Count > 1) {while
(Pmove->next!= NULL) {
if (Pmove->element > Pmove->n ext->element) {
int temp;
temp = pmove->element;
Pmove->element = pmove->next->element;
pmove->next->element = temp;
}
Pmove = pmove->next;
}
count--;
Move back to the first node
pmove = pnode->next;
}
printf ("%s function execution, single linked table bubbling sort succeeded \ n", __function__);
Printlist (pnode);
return pnode;
}