Question: struct ListNode { int element; ListNode *next; }; Write a c++ code for all the questions below based on the provided definition of a linked

struct ListNode { int element; ListNode *next; };

Write a c++ code for all the questions below based on the provided definition of a linked list node. a)Write a constructor for this struct that initializes an object to the default value, zero and NULL, respectively, and to constructor parameters, e and n, respectively.

b) Use this constructor to create dynamically an object called newNode with the element value 7.

c) Insert newNode after the pointer called prevNode. What is the running time of this operation?

d) Write code that deletes a node after prevNode and displays the value of an element of the deleted node on the screen using cout. What is the running time of this operation?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!