Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
Expert Solution & Answer
Book Icon
Chapter 3, Problem 25C

Explanation of Solution

Algorithm to concatenate two singly linked list:

The algorithm to concatenate two singly linked list “L” and “M” into single list “L'” is given below:

Algorithm:

Input: Two singly linked list “L” and “M”.

Output: Concatenate the two singly linked lists into single list “L'”.

Concatenate(L, M):

  //Create new node for list "L"

  Create a new node "n"

/*Call getHead() method using singly linked list "L" to assign the head of list as "n". */

  n = L.getHead();

/*Loop executes until the next node of list is not equal to "null". */

  while (n.getNext()!= null)

  //Assign next node as "n"

  n = n.getNext();

/*Call setNext() method to set the next node as head of singly linked list "M"...

Blurred answer
03:47
Students have asked these similar questions
The special case(s) when deleting a node in a linked list is/are: а. The list is empty. O b. All c. The node to be deleted is the first node. O d. There is only one node in the list.
Pls send me answer of this question immidiately with explanation and i will give you like sure sir.
What are the requirements for determining if a linked list T is empty if T is one of the following: (i) a simple singly linked list, (ii) a headed singly linked list, (iii) a simple circularly linked list, or (iv) a headed circularly linked list?
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education