File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments