Instructions: This assignment involves using recursive method. Write a program that reverses a LinkedList. Save the code
Posted: Sat Nov 27, 2021 10:40 am
Instructions:
This assignment involves using recursive method. Write a program
that reverses a LinkedList.
Save the code in jGRASP, then save it in c:\myjava and run
it.
/*******************
Name:
Date:
Notes:
*******************/
// Java program for reversing the linked list
class MyLinkedList {
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) {
add content
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) {
MyLinkedList list = new MyLinkedList();
add content }
}
This assignment involves using recursive method. Write a program
that reverses a LinkedList.
Save the code in jGRASP, then save it in c:\myjava and run
it.
/*******************
Name:
Date:
Notes:
*******************/
// Java program for reversing the linked list
class MyLinkedList {
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) {
add content
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) {
MyLinkedList list = new MyLinkedList();
add content }
}