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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!