Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This lab is concerned with a doubly linked list of integers. The initial program as written creates the nodes in the following list: The program

This lab is concerned with a doubly linked list of integers. The initial program as written creates the nodes in the following list:

The program does not place the links between the nodes. Add code that links them as shown in the diagram. Dont forget to set the NULL pointers!

After the call to print in main, create a node pointed to by new_guy. Place the value 4 in the node. Change pointers so that the new node is inserted between the nodes containing 3 and 5.

Write a function called rprint. rprint takes a pointer to the first node of a doubly linked list as its parameter. It prints the nodes in the list in reverse order. It must first move through the list to find the last node. It then moves along back pointers printing the elements. Do not write a recursive reverse print!

Add calls to print and rprint at the spots indicated to print the list after the insertion.

Place your completed Lab11.cpp source file on Blackboard.

1. When we wrote ordered linked list functions in class, we kept track of a previous pointer. Would a previous pointer be necessary with a doubly linked list? Explain.

2. Consider the following box and arrow diagram:

image text in transcribed

What is the name of each of the following pointers (the only available pointer to a node is ptr):

a.

b.

c.

d.

e. (in terms of ptr)

3. Use the diagram from Problem 2. Show a sequence of statements that will remove the node containing 3 from the list (nodes containing 1 and 5 should then be linked). Add the node containing 3 to free store at the end. Dont worry that there are not any pointers pointing to the remaining list.

ptr is the only pointer you should use to access the list.

here is the code on c++

#include  #include  using namespace std; /* CIS 251 Lab 11 Creates a doubly linked list, inserts a node, prints the list in forward order before and after insertion and in reverse order after insertion. */ struct dnode { int number; // data dnode *next, // pointer to next node in list *back; // pointer to previous node in list }; typedef dnode* dptr; // a pointer type for doubly linked list nodes void print (dptr front); int main(int argc, char *argv[]) { dptr ptr1, ptr2, ptr3, new_guy; // create three element double linked list ptr1 = new dnode; ptr1 -> number = 1; ptr2 = new dnode; ptr2 -> number = 3; ptr3 = new dnode; ptr3 -> number = 5; // *****link the nodes here ****** cout  next) cout  number   ptr

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions