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

Class DLL

12_LinkedList.java/DLL.java:1–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1public class DLL {
2 public static 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
14 public static Node head;
15 public static Node tail;
16 public static int size;
17
18 public void addFirst(int data) {
19 size++;
20 Node newNode = new Node(data);
21 if(head == null) {
22 head = tail = newNode;
23 return;
24 }
25
26 head.prev = newNode;
27 newNode.next = head;
28 head = newNode;
29 }
30
31 public void print() {
32 Node temp = head;
33 while(temp != null) {
34 System.out.print(temp.data+"<->");
35 temp = temp.next;
36 }
37 System.out.println("null");
38 }
39
40 public int removeFirst() {
41 if(head == null) {
42 return Integer.MIN_VALUE;
43 }
44 size--;
45 if(head == tail) {
46 int val = head.data;
47 head = tail = null;
48 return val;
49 }
50 int val = head.data;
51 head = head.next;
52 head.prev = null;
53 return val;
54 }
55
56 public void reverse() {
57 Node curr = head;
58 Node prev = null;
59 Node next;
60 while(curr != null) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected