Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781119278023
Author: Michael T. Goodrich; Roberto Tamassia; Michael H. Goldwasser
Publisher: Wiley Global Education US
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
Create two singly linked lists A and B to represents elements in the following set A and B respectively. 3. A = { 5, 6, 8, 9, 10, 11} B = { 1, 6, 2, 9, 3, 11, 4} Develop an algorithm and implement the same to represent only intersection of two lists A and B and print the same.
Implement a circular singly linked list in C programming language. Create functions for the ff: 1. Transversal 2. Insertion of element (at the beginning, in between nodes, and at the end) 3. Deletion of element 4. Search 5. Sort
Write a java program class for a singly linked list with Insertion from head, tail and middle
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