MCPcopy Create free account
hub / github.com/apna-college/Alpha / DoubleLL

Class DoubleLL

12_LinkedList.java/DoubleLL.java:1–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1public class DoubleLL {
2 public class Node {
3 int data;
4 Node next;
5 Node prev;
6
7 public Node(int data) {
8 this.data = data;
9 this.next = null;
10 this.prev = null;
11 }
12 }
13 public static Node head;
14 public static Node tail;
15 public static int size;
16
17 //add
18 public void addFirst(int data) {
19 Node newNode = new Node(data);
20 size++;
21 if(head == null) {
22 head = tail = newNode;
23 return;
24 }
25
26 newNode.next = head;
27 head.prev = newNode;
28 head = newNode;
29 }
30
31 //print
32 public void print() {
33 Node temp = head;
34 while(temp != null) {
35 System.out.print(temp.data +"<->");
36 temp = temp.next;
37 }
38 System.out.println("null");
39 }
40
41 //remove - removeLast
42 public int removeFirst() {
43 if(head == null) {
44 System.out.println("DLL is empty");
45 return Integer.MIN_VALUE;
46 }
47
48 if(size == 1) {
49 int val = head.data;
50 head = tail = null;
51 size--;
52 return val;
53 }
54 int val = head.data;
55 head = head.next;
56 head.prev = null;
57 size--;
58 return val;
59 }
60

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…