Question
1) create Node class that implement double linked list 2) create double linked list class 3) implement add method just make this single-linked list into
1) create Node class that implement double linked list
2) create double linked list class
3) implement add method
just make this single-linked list into double-linked list :
NODE:
public class Node {
int data;
Node next;
SingleLinkedList:
public class SingleLinkedList {
Node head = null;
Node tail = null;
int size = 0;
public void add(int element) {
if (size == 0) {
Node temp = new Node();
temp.data = element;
head = temp;
tail = temp;
size++;
} else {
Node temp = new Node();
temp.data = element;
tail.next = temp;
tail = temp;
size++;
}
}
MAIN :
public class Main {
public static void main(String[] args) {
SingleLinkedList ls = new SingleLinkedList();
ls.add(10);
ls.add(20);
ls.add(30);
ls.add(40);
System.out.println("orginal LinkedList: ");
ls.print();
System.out.println("------------------------------------");
System.out.println("print after adding: ");
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started