Computer Science: An Overview: Global Edition (12th Edition)

Published by Pearson Higher Education
ISBN 10: 1292061162
ISBN 13: 978-1-29206-116-0

Chapter 8 - Data Abstractions - Chapter Review Problems - Page 409: 10

Answer

See the explanation

Work Step by Step

The correct routine for inserting NewEntry immediately after the entry called PreviousEntry in a linked list is Routine 1. Explanation: Routine 1 correctly inserts NewEntry into the linked list by following these steps: 1. Copy the value in the pointer field of PreviousEntry into the pointer field of NewEntry. 2. Change the value in the pointer field of PreviousEntry to the address of NewEntry. This sequence of steps ensures that the NewEntry is properly inserted after the PreviousEntry in the linked list. By copying the value in the pointer field of PreviousEntry into the pointer field of NewEntry, the link between PreviousEntry and the subsequent entry is preserved. Then, by changing the value in the pointer field of PreviousEntry to the address of NewEntry, the link between PreviousEntry and NewEntry is established. On the other hand, Routine 2 is incorrect because it swaps the order of the steps: 1. Change the value in the pointer field of PreviousEntry to the address of NewEntry. 2. Copy the value in the pointer field of PreviousEntry into the pointer field of NewEntry. In Routine 2, the link between PreviousEntry and the subsequent entry is lost before it is copied into the pointer field of NewEntry. This results in the loss of the original link and the incorrect insertion of NewEntry into the linked list. Therefore, Routine 2 is not a correct way to insert NewEntry immediately after PreviousEntry in a linked list.
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.