-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDLL.java
More file actions
49 lines (45 loc) · 1.1 KB
/
DLL.java
File metadata and controls
49 lines (45 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.company;
public class DLL{
Node head;
public Node addVertex(int u){
Node newNode = new Node(u);
if (head == null) {
head = newNode;
}
else{
Node temp = head;
while(temp.prev!=null){
temp = temp.prev;
}
temp.prev = newNode;
}
return newNode;
}
public Node check(int u){
Node temp = head;
int flag = 0;
while(temp != null){
if(temp.data == u){
flag = 1;
break;
}
temp = temp.prev;
}
if (flag!=0)
return temp;
return null;
}
public void display(){
Node temp = head;
while(temp!=null){
Node yet = temp;
System.out.print(temp.data+" ->");
while(yet.next != null){
System.out.print(yet.data+" ->");
yet = yet.next;
}
System.out.println();
temp = temp.prev;
}
}
}