February 2020
Beginner to intermediate
616 pages
15h 16m
English
To sort the linked list, we will employ the services of two pointers—temp1 and temp2. The temp1 pointer is set to point at the first node, and temp2 is set to point at the next node as follows:

We will be sorting the linked list in ascending order, so we will keep the smaller values toward the beginning of the list. The data members of temp1 and temp2 will be compared. Because temp1->data is greater than temp2->data, that is, the data member of temp1 is larger than the data member of temp2, their places will be interchanged (see the following diagram). After interchanging the data members of the nodes pointed ...
Read now
Unlock full access