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

Explanation of Solution

Algorithm to compare two circularly linked lists is same:

The algorithm to compare two circularly linked lists “L” and “M” are same sequence of elements given below:

Algorithm:

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

Output: Return true when two circular linked lists “L” and “M” are same sequence of elements. Otherwise, return false.

equal(L :Circularly linked list, M Circularly linked list):

    //Create new node for list "L" and "M"

  Create a new node "a" and "b"

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

  a = L.getHead();

/*Call getHead() method using circularly linked list "M" to assign the head of list as "b". */

  b = M.getHead();

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

  while (a.getNext()!= null || b.getNext()!= null)

  {

/*Loop executes until both list elements are not equal. */

  while(a.getElement() != b.getElement())

  //Assign next node as "b"

  b = b.getNext();

  //Assign next node as "a"

  a = a.getNext();

/*Call getHead() method using circularly linked list "M" to reassign the head of list as "b". */

  b = M...

Blurred answer
Students have asked these similar questions
Given a list of integers, we want to know whether it is possible to choose a subset of some of the integers, such that the integers in the subset adds up to the given sum recursively. We also want that if an integer is chosen to be in the sum, the integer next to it in the list must be skipped and not chosen to be in the sum. Do not use any loops or regular expressions. Test cases: skipSum([2, 5, 10, 6], 12) true skipSum([2, 5, 10, 6], 7) false skipSum([2, 5, 10, 6], 16) false Given code: public static boolean skipSum (List list, int sum) { // call your recursive helper method return skipSumHelper (list, e, sum); 1. 2. 3. 4.
Given a string formed with 0’s and 1’s. The string is marked with a special character X that represents the middle of the string (for example: 0101011X1101010). Write an algorithm to check whether the string is palindrome or not: (a) If the string is stored as an array (b) If the string is stored as a singlv linked list
Consider there is a singly linked list of integers. Find the positive integers and negative integers in list and keeping them in the same order, rearrange negative integers in the start of the list and positive at the end of the list. Also remove the duplicate numbers from list. Sample output attached below. Note: Output is attached Solve as soon as possible with in 60 minutes Use c++ language
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