Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++: Code: include using namespace std; struct Node{ char val; Node* next; }; class SLL{ private: Node* headPtr; public: Node* getHeadPtr(){ return headPtr; } void

image text in transcribed

C++:

Code:

include using namespace std;

struct Node{ char val; Node* next;

};

class SLL{ private:

Node* headPtr;

public: Node* getHeadPtr(){

return headPtr; }

void merge(SLL x){ }

};

Write a function to merge two singly linked lists. This singly linked list is similar to the one we discussed in the lecture. The linked list we use in this question is NOT a circular list. Suppose we have two singly linked lists, the method merge) in SLL class will take one SLL object as argument, merge this list to the current list. The nodes from these two lists should be merged alternatively. For example, we have following two lists. 8. Suppose the first list is in object a, the second list is in object b. After invoke a.merge(b), the list in object a will be the following. x. Please implement the merge0 method listed in the skeleton code. Write down your solution after the skeleton code. To save space, we did not list other methods inside class, such as constructor and destructor etc. However, one method getHeadPtr() is listed. Your solution merge) method will need getHeadPtr(), but not other methods. To simplify discussion, we assume neither list a nor list b can be empty. (20 points)

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

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions