- Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathExercise_2.java
More file actions
Latest commit
52 lines (39 loc) · 1.12 KB
/
Copy pathExercise_2.java
File metadata and controls
52 lines (39 loc) · 1.12 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
publicclassStackAsLinkedList {
StackNoderoot;
staticclassStackNode {
intdata;
StackNodenext;
StackNode(intdata)
{
//Constructor here
}
}
publicbooleanisEmpty()
{
//Write your code here for the condition if stack is empty.
}
publicvoidpush(intdata)
{
//Write code to push data to the stack.
}
publicintpop()
{
//If Stack Empty Return 0 and print "Stack Underflow"
//Write code to pop the topmost element of stack.
//Also return the popped element
}
publicintpeek()
{
//Write code to just return the topmost element without removing it.
}
//Driver code
publicstaticvoidmain(String[] args)
{
StackAsLinkedListsll = newStackAsLinkedList();
sll.push(10);
sll.push(20);
sll.push(30);
System.out.println(sll.pop() + " popped from stack");
System.out.println("Top element is " + sll.peek());
}
}