Question

2- Given following data structures of a double linked list :    class ListNode      {...

2- Given following data structures of a double linked list :

   class ListNode

     {

        String info ;

        ListNode prev ;

       ListNode next ;

          …….

     }

  

Write a Java method which prints the content of double linked list in reverse order.

Homework Answers

Answer #1

/* passing the head of the list */
   public static void print_reverse(ListNode head) {
       ListNode temp = head;
       /* go to the last node of the ListNode */
       while (temp.next != null) {
           temp = temp.next;
       }
       /* Print node and keep on coming back */
       while (temp.prev != null) {
           System.out.println(temp.info + "\t");
           temp = temp.prev;
       }
   }

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Given this definition of a generic Linked List node: public class LLNode {     private T...
Given this definition of a generic Linked List node: public class LLNode {     private T data;     private LLNode next;     public LLNode(T data, LLNode next) {           this.data = data;           this.next = next;     }     public void setNext(LLNode newNext){ next = newNext; }     public LLNode getNext(){ return next; }     public T getData() {return data;} } Write the findMinimumNode method body. This method returns the linked list node that contains the minimum value in the...
Data Structures using C++ Searching a Linked List Here are the declarations for a simple unsorted...
Data Structures using C++ Searching a Linked List Here are the declarations for a simple unsorted linked list of ints that ends in a null pointer. //=============================================================== class Cell { friend class UList; private: int data; Cell* next; Cell( int dt, Cell* nx=nullptr ) : data(dt), next(nx) {} }; //=============================================================== class UList { private: Cell* head = nullptr;    // stationary head pointer. Cell* scan = nullptr;          // for walking down the List. Cell* follow = nullptr; public: void find( int...
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete....
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete. Return true or false to indicate success or failure. Delete the memory the node was using The algorithm for deleting a Node to a Linked List (general case): ● Begin at the head. ● Compare the id to the current node. ● If search id > current id, stop. ● Detach the current Node ○ current->previous->next = current->next ○ current->next->previous = current->previous ● Deallocate...
JAVA *** All data structures, including array operations, queues, stacks, linked lists, trees, etc need to...
JAVA *** All data structures, including array operations, queues, stacks, linked lists, trees, etc need to be implemented by you. Write a menu driven program that implements the following doubly linked list operations : INSERT (at the beginning) INSERT_ALPHA (in alphabetical order) DELETE (Identify by contents, i.e. "John", not #3) COUNT CLEAR
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
java Consider the following class definition: public class Circle { private double radius; public Circle (double...
java Consider the following class definition: public class Circle { private double radius; public Circle (double r) { radius = r ; } public double getArea(){ return Math.PI * radius * radius; } public double getRadius(){ return radius; } } a) Write a toString method for this class. The method should return a string containing the radius and area of the circle; For example “The area of a circle with radius 2.0 is 12.1.” b) Writeaequalsmethodforthisclass.ThemethodshouldacceptaCircleobjectasan argument. It should return...
The main goal is to implement two recursive methods, each is built to manipulate linked data...
The main goal is to implement two recursive methods, each is built to manipulate linked data structures. To host these methods you also have to define two utterly simplified node classes. 1.) Add a class named BinaryNode to the project. This class supports the linked representation of binary trees. However, for the BinaryNode class Generic implementation not needed, the nodes will store integer values The standard methods will not be needed in this exercise except the constructor 2.) Add a...
I need a method for public void ****************** write the method “insertDoubles” that for each value...
I need a method for public void ****************** write the method “insertDoubles” that for each value found in an integer linked list it inserts that value doubled after the original. The method should return nothing and take in in no parameters. If the list is empty, then the method should do nothing. To avoid infinite loops you need to move the iterator past the newly inserted value. here is the provided code public class Question02 { public class ListNode//public for...
Part 1 Given the following code: public class MyClass { private double score; private String studentID;...
Part 1 Given the following code: public class MyClass { private double score; private String studentID; //code of the class ..... } //end of MyClass Code a default constructor and an overloaded constructor of MyClass that will assign values to its two instance fields: Please write in JAVA Part 2 Continue from question about, code an mutator of instance field called studentID:
1. Build a double linked list with 5 in the first node following the instructions: Insert...
1. Build a double linked list with 5 in the first node following the instructions: Insert a node with 3 at the top of the list Insert a node with 10 at the bottom of the list Insert a node with 7 between nodes with 5 and 10 2. Start deleting nodes from the list in the following order; Delete the node with 7 Delete the node with 3 Delete the node with 10 3. Print the resulting list forward...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT