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
I need to develop and run a program that prompts the user to enter a positive integer n, and then calculate the value of n factorial n! = multiplication of all integers between 1 and n, and print the value n! on the screen. This is for C*.
I need to develop and run a C* program to sum up integers from 1 to 100, and print out the sum value on the screen. Can someone help please?
Given the schema below for the widgetshop, provide a schema diagram. Schema name Attributes Widget-schema Customer-schema (stocknum, manufacturer, description, weight, price, inventory) (custnum, name, address) Purchased-schema (custnum, stocknum, pdate) Requestedby-schema (stocknum, custnum) Newitem-schema (stocknum, manufacturer, description) Employee-schema (ssn, name, address, salary) You can remove the Newitem-schema (red).
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning