-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCollections.java
More file actions
82 lines (79 loc) · 2.2 KB
/
Collections.java
File metadata and controls
82 lines (79 loc) · 2.2 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
public class Collections {
static class Node{
String data;
Node next;
Node prev;
Node(String d){
data = d;
next = null;
prev = null;
}
}
Node head;
public Collections(){
head = null;
}
public void add(String d){
Node n = new Node(d);
if(head==null)
{
head=n;
n.next = null;
n.prev = null;
}
else{
Node temp = head;
while(temp.next!=null)
temp = temp.next;
temp.next = n;
n.prev = temp;
n.next = null;
}
}
public void delete(String d){
Node temp = head;
if(head.data.equals(d)){
head = temp.next;
return;
}
while(temp.next!=null){
if(temp.next.data.equals(d)){
temp.next = temp.next.next;
return;
}
temp = temp.next;
}
}
public void printList() {
Node temp = head;
while (temp != null) {
if (temp.data.contains(".")) {
System.out.println(temp.data.substring(0, temp.data.lastIndexOf(".")));
}
else {
System.out.println(temp.data);
}
temp = temp.next;
}
}
public boolean search(String d){
int i = 1;
boolean flag = false;
Node current = head;
if(head == null) {
return false;
}
while(current != null) {
if(current.data.equals(d)) {
flag = true;
break;
}
current = current.next;
i++;
}
return flag;
}
public boolean isEmpty(){
return head == null;
}
}