Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Draw a diagram showing the structure of the list and the position of the pointer p for a and b. Redraw the complete picture

1. Draw a diagram showing the structure of the list and the position of the pointer p for a and b. Redraw the complete picture after each assignment statement is completed.

class node {

public:

node( int x, node* ptr = NULL )

{

data = x; next = ptr;

}

int data;

node* next;

};

(a) node *p = nullptr;

p = new node( 10 );

p->next = new node( 20, p );

p = new node( 30, p );

(b) node *p = nullptr;

p = new node( 30 );

p = new node( 20, p );

p = new node( 10, p );

2. Tracing List Algorithms

// Use node type defined in problem 1.

void fun( node*& head, int x )

{

node* p2 = nullptr;

node* p1 = head;

while ( p1 != NULL && x > p1->data )

{

p2 = p1;

p1 = p1->next;

}

if ( p2 == nullptr )

{

head = new node( x, p1 );

}

else

{

p2->next = new node( x, p1 );

}

(a)If the function is called as follows: fun( head, 15 ); where head points to the list: draw a picture of the list pointed to by head after the call is complete:

(b) If the function is called as follows: fun( head, 40 ); where head points to the list: draw a picture of the list pointed to by head after the call is complete: head 10

Tks for any help that you can provide

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions