-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathStack.java
More file actions
33 lines (29 loc) · 799 Bytes
/
Stack.java
File metadata and controls
33 lines (29 loc) · 799 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
import java.util.*;
public class Stack
{
Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
Stack<Integer> stack = new Stack<Integer>();
for(int i=0;i<7;i++){
stack.push(i);
}
System.out.println(stack);
//insert element
stack.push(20);
System.out.println(stack);
//remove element from last
stack.pop();
System.out.println(stack);
//check the stack is empty
System.out.println(stack.empty());
//peek return the index of element
System.out.println(stack.peek());
// Iterator instace
Iterator<Integer> itr
= stack.iterator();
// Printing the stack
while (itr.hasNext()) {
System.out.print(itr.next() + " ");
}
}
}