Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE IMPLEMENT BELOW CODE OF REVERSE METHOD USING GENERIC FUNCTION. public class ReverseLinkedList { static Node head; static class Node { int data; Node next;

PLEASE IMPLEMENT BELOW CODE OF REVERSE METHOD USING GENERIC FUNCTION.

public class ReverseLinkedList { static Node head; static class Node { int data; Node next; Node(int d) { data = d; next = null; } } /* Function to reverse the linked list */ Node reverse(Node node) { Node prev = null; Node current = node; Node next = null; while (current != null) { next = current.next; current.next = prev; prev = current; current = next; } node = prev; return node; } // prints content of double linked list void printList(Node node) { while (node != null) { System.out.print(node.data + " "); node = node.next; } } public static void main(String[] args) { ReverseLinkedList list = new ReverseLinkedList(); list.head = new Node(1); list.head.next = new Node(2); list.head.next.next = new Node(3); list.head.next.next.next = new Node(4); System.out.println("Given Linked list"); list.printList(head); head = list.reverse(head); System.out.println(""); System.out.println("Reversed linked list "); list.printList(head); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions

Question

=+ What are the information and consultation requirements?

Answered: 1 week ago

Question

=+ Should the MNE belong (why, why not)?

Answered: 1 week ago