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 30C

Explanation of Solution

Algorithm to split the circularly linked list:

The algorithm to split the two half of circularly linked list “L” is given below:

Algorithm:

Input: circularly linked list “L” contains even number of nodes.

Output: Split the “L” into two half of circularly linked list “L” and “M”.

split(L):

  //Create circularly linked list "M"

  CircularlyLinkedList M = new CircularlyLinkedList()   

/*Create node for temporary use and assign tail of list "L" into it. */

  Node temp = L.tail;

//Loop executes until the half of size of list "L"

  for i less than half of "L" size, then

/*Get next node of tail and assign it into "temp" node. */

  temp = temp.getNext();

/*Get the next node of "temp" node and assign it into tail of "M" list. */

  M.tail = temp.getNext();

/*Set the next node of "temp" node as the tail of list "L". */

  temp.setNext(L.tail);

//Loop executes until the half of size of list "L"

  for i less than half of "L" size, then

/*Get next node of tail and assign it into "temp" node...

Blurred answer
Students have asked these similar questions
The optimal number of elements for a linked list is unknown.Which of the following is the longest?
Given a singly linked list, print reverse of it using a recursive function printLinkedList( node *first ) where first is the pointer pointing to the first data node. For example, if the given linked list is 1->2->3->4, then output should be: 4 3 2 1 (note the whitespace in between each data value)
Computer Science please solve this problem as soon as possible Write a function to insert the element into the linked list the given number X. E.g., for a given set of integers, [2, 4, 12, 6, 5, 3], the linked list is 2->4->12->6->5->3. For a given number, (X=15), the count will be 11 that are (2,4), (2,12), (2,6), (2,5), (2,3), (4,6), (4,5), (4,3), (6,5), (6,3), (5,3).
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