# Solutions to Chapter 15

Review Questions
1. a. True
3. a. True
5. a. the order structure of elements
7. b. last in-first-out.
9. a. anywhere in the list
11. d. none of the above
13. b. queue
15. a. pop
17. d. dequeue
19. c. data structure

Exercises
21. At the beginning of the search, pCur is pointing the first node and pPre is null.
So, the second statement (pPre = pPre->link) creates a run-time error.
The correct code is:
pPre = pCur;

23. The code to delete a node in the middle of a list is shown below/ Since this is the
same code to delete from the beginning of the list, using a dummy node does
simplify the insert for a linked list by eliminating the special case of deleting the
first node.
free (pCur);

25.

Since this is the same code as what is used to add a node at the beginning of the
list, using a dummy node can simplify the operations to a linked list by eliminating the special case of adding the first data node.
27. We append the second linked list to the first linked list.

93

7 10 14 23 33 56 66 70 80 Figure 15-4 Solution to Exercise 35 .94 Solutions to Chapter 15 29. See Figure 15-1 3 5 7 9 11 13 S1 S2 Figure 15-1 Solution to Exercise 29 31. See Figure 15-3. See Figure 15-4. 31 Q1 19 Q2 20 11 Q3 Figure 15-2 Solution for Exercise 31 33. See Figure 15-2. 5 12 9 5 9 12 9 5 12 5 12 12 5 9 9 Figure 15-3 Solution to Exercise 33 35.

// Other data goes here } DATA. traverses it.key < minPtr->key) minPtr = &(pWalker->data). pWalker = pWalker->link. } NODE. DATA* minPtr = NULL. See Figure 15-5. typedef struct { KEY_TYPE key.Problems 37. /* ================== findMinimum =============== This function accepts a linked list. } // while } // if list !empty } return minPtr. and returns the data in node with minimum key value. minPtr = &(pWalker->data). Pre pList is a pointer to a linked list Post returns pointer to data with minimum key NULL if list is empty */ DATA* findMinimum (NODE* pList) { // Local Declrations NODE* pWalker. // findMinimum 95 . typedef struct nodeTag { DATA data. while (pWalker) { if (pWalker->data. 7 10 14 23 33 56 44 66 50 70 80 Figure 15-5 Solution to Exercise 37 Problems 39. // Statements if (pList) { pWalker = pList. struct nodeTag* link. Program 15-1 Solution to Problem 39 // Global Declarations typedef int KEY_TYPE. See Program 15-1.