Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the code fragment: struct NodeType { int data; NodeType* next; }; NodeType* p; NodeType* q; p = new NodeType; p->data = 12; p->next =

Given the code fragment:

struct NodeType

{

int data;

NodeType* next;

};

NodeType* p;

NodeType* q;

p = new NodeType;

p->data = 12;

p->next = NULL;

q = new NodeType;

q->data = 5;

q->next = p;

Which of the following expressions has the value 12?

i) q

ii) q->data

iii) q->next->data

iv) q->next

v) None of the above

2) Given the declarations:

struct ListNode

{

float volume;

ListNode* next;

};

ListNode* headPtr;

Assume that headPtr is the external pointer to a linked list of many nodes. Which statement deletes the first node? (Ignore deallocation of the node.)

i) headPtr = headPtr->next;

ii) *headPtr = headPtr->next;

iii) headPtr->next = headPtr->next->next;

iv) headPtr->(*next) = headPtr->next->next;

v) none of the above

3) Given the declarations:

struct ListNode

{

float volume;

ListNode* next;

};

ListNode* headPtr;

Assume that headPtr is the external pointer to a linked list of many nodes. Which statement deletes the second node? (Ignore deallocation of the node.)

i) headPtr = headPtr->next;

ii) *headPtr = headPtr->next;

iii) headPtr->next = headPtr->next->next;

iv) headPtr->(*next) = headPtr->next->next;

v) none of the above

4) Given the declarations:

struct NodeType

{

int score;

NodeType* next;

};

NodeType* somePtr;

Write a single C++ statement that will deallocate (that is, return to the free store) the dynamic node that is currently pointed to by somePtr: __________________

5) Given the declarations:

struct NodeType

{

int data;

NodeType* next;

};

NodeType* headPtr; //External pointer to a linked list

NodeType* p;

the following code sums all the components in a list:

sum = 0;

p = headPtr;

while ( /* Loop condition */ )

{

sum = sum + p->data;

p = p->next;

}

Write the missing loop condition: ____________________

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

Advances In Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions