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

Explanation of Solution

Method reverse()in singly linked list:

/*Define the reverse() method to reverse the elements from singly linked list. */

public void reverse()

{

  //Create node and assign it as "null"

  Node<E> prevNode = null;

  //Create node and assign it as "head"

  Node<E> hNode = head;

//Check whether the "hNode" is not equal to "null"

  while (hNode != null)

  {

  //Get next node of head and assign it into "temp"

  Node<E> temp = hNode.getNext();

/*Set next node of head is assigned with "prevNode". */

  hNode...

Blurred answer
Students have asked these similar questions
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)
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.
A singly linked list can perform insertion and deletion of nodes from both ends in constant time
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