-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basics of stack (push, peek, size, pop)
- Loading branch information
1 parent
5c46871
commit e76828c
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import java.util.*; | ||
public class Program | ||
{ | ||
public static void main(String[] args) | ||
{ | ||
Stack<Integer> st=new Stack<>(); | ||
st.push(10); | ||
System.out.println(st+" "+st.peek()+" "+st.size()); | ||
st.push(20); | ||
System.out.println(st+" "+st.peek()+" "+st.size()); | ||
st.push(30); | ||
System.out.println(st+" "+st.peek()+" "+st.size()); | ||
st.push(40); | ||
System.out.println(st+" "+st.peek()+" "+st.size()); | ||
st.push(50); | ||
System.out.println(st+" "+st.peek()+" "+st.size()); | ||
st.pop(); | ||
System.out.println(st+" "+st.peek()+" "+st.size()); | ||
st.pop(); | ||
System.out.println(st+" "+st.peek()+" "+st.size()); | ||
st.pop(); | ||
System.out.println(st+" "+st.peek()+" "+st.size()); | ||
st.pop(); | ||
System.out.println(st+" "+st.peek()+" "+st.size()); | ||
st.pop(); | ||
System.out.println(st+" "+st.peek()+" "+st.size()); | ||
st.pop(); | ||
//till here all elements are gone | ||
//so when we again print st.peek it will not print it will give run time error | ||
//so we do not write st.peek function | ||
System.out.println(st+" "+st.size()); | ||
//size comes as zero | ||
} | ||
} |