Skip to content

Commit d8eeed0

Browse files
authored
Stack java
Implementation Stack java
1 parent ae5f2a4 commit d8eeed0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Stack.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.*;
2+
3+
public class Stack
4+
{
5+
Scanner sc = new Scanner(System.in);
6+
public static void main(String[] args) {
7+
Stack<Integer> stack = new Stack<Integer>();
8+
for(int i=0;i<7;i++){
9+
stack.push(i);
10+
}
11+
System.out.println(stack);
12+
//insert element
13+
stack.push(20);
14+
System.out.println(stack);
15+
//remove element from last
16+
stack.pop();
17+
System.out.println(stack);
18+
//check the stack is empty
19+
System.out.println(stack.empty());
20+
//peek return the index of element
21+
System.out.println(stack.peek());
22+
// Iterator instace
23+
Iterator<Integer> itr
24+
= stack.iterator();
25+
26+
// Printing the stack
27+
while (itr.hasNext()) {
28+
System.out.print(itr.next() + " ");
29+
}
30+
31+
32+
}
33+
}

0 commit comments

Comments
 (0)