-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackLinkedList.java
More file actions
50 lines (44 loc) · 1016 Bytes
/
StackLinkedList.java
File metadata and controls
50 lines (44 loc) · 1016 Bytes
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
public class Stack {
LinkedList linkedList;
public Stack() {
linkedList = new LinkedList();
}
// Push method
public void push(int value) {
linkedList.insertInLinkedList(value, 0);
System.out.println("Inserted " + value + " in Stack");
}
// isEmpty
public boolean isEmpty() {
if (linkedList.head == null) {
return true;
} else {
return false;
}
}
// Pop method
public int pop() {
int result = -1;
if (isEmpty()) {
System.out.println("The Stack is Empty!");
} else {
result = linkedList.head.value;
linkedList.deletionOfNode(0);
}
return result;
}
// Peek Method
public int peek() {
if (isEmpty()) {
System.out.println("The Stack is Empty!");
return -1;
} else {
return linkedList.head.value;
}
}
// Delete Method
public void deleteStack() {
linkedList.head = null;
System.out.println("The Stack is deleted");
}
}