Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

struct Node { int data; Node* next; } 1. Write a function to concatenate two linked lists. Given lists l1 = (2, 3, 1) and

struct Node { int data; Node* next; }

1. Write a function to concatenate two linked lists. Given lists l1 = (2, 3, 1) and l2 = (4, 5), after return from concatenate(l1, l2) the list l1 should be changed to be l1 = (2, 3, 1, 4, 5). Your function should not change l2 and should not directly link nodes from l1 to l2 (i.e. the nodes inserted into l1 should be copies of the nodes from l 2.)

void concatenateList(Node*& h1, Node* h2 ); // // Precondition: h1 and h2 are head pointers of linked lists. // The lists may be empty or non-empty. // // Postcondition: A copy of list h2 is concatenated (added to the end) // of list h1. List h2 should be unchanged by the function. // NOTE: The nodes added to the list h1 must be copies of the // nodes in list h2.

2. Write a function to insert a number as the new ith node of a linked list. Nodes initially in positions i, i+1, ..., n should be shifted to positions i+1, i+2, ..., n+1. Thus, the length of the list will increase by 1. If the original list contains fewer than i-1 nodes, then the number should be inserted at the end of the list.

3. Write a function to remove duplicate entries in a linked list. For example, given the list (5, 2, 2, 5, 3, 9, 2) as input, your function should change the list so that on return from the function it contains (5, 2, 3, 9).

4. Write a function that returns the maximum data value in a linked list. You should assume that the list contains non-negative integer values in the data fields of all nodes. Given a list list1 = (2, 3, 9, 1, 5), after execution of the statement max = maxElem(list1); the variable max should be equal to 9. If the list is empty, you should return the value -1.

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

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions