Deletion from the Tail
Add deletion capability to the project you worked on in Programming Exercise 4. For this you will need to maintain a pointer to the node thattailpoints to. The interface, after node 4 from Figure 12-52 is deleted, is shown in Figure 12-53.
Figure 12-54 shows the deletion process as a progression of steps. A temporary pointer (temp) points to the node preceding thetail. Using temp, the node at the end of the list can be deleted (temp->next). Thentailcan be assigned the value stored intemp. The trick to this assignment is to find the position fortemp. This can be done using awhileloop that repeatededly assigns temp the valuetemp->nextuntiltemp->next->nextis the null pointer.
Programming Exercise 4
Insertion at the End of the List
At this point, your program can insert and delete only from the front of the list (the head node). The result is that data values are stored in descending order from the head node. Data could be stored in ascending order if nodes were inserted at the end of the list instead of from the front. This necessitates a list with a pointer to the tail node as shown in Figure 12-51.
Modify your tutorial project (you can make a copy and rename it) so that all insertions take place at the tail. You do not need to implement node deletion. The typical interface display should show an ordered list, as in Figure 12-52:
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here