Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package xlot;
- import java.util.Scanner;
- import java.util.Arrays;
- public class Xlot
- {
- public int size;
- public int[] stack;
- public int tos;
- Xlot()
- {
- }
- Xlot(int s)
- {
- size=s;
- stack=new int[size];
- tos=-1;
- }
- public void push(int j)
- {
- stack[++tos]=j;
- }
- public int pop()
- {
- return stack[tos--];
- }
- public int peek()
- {
- return stack[tos];
- }
- public boolean isFull()
- {
- return (tos==size-1);
- }
- public boolean isEmpty()
- {
- return(tos==-1);
- }
- public static void main(String[] args)
- {
- System.out.println("enter stack size : ");
- Scanner i = new Scanner(System.in);
- int temp1=i.nextInt();
- Xlot ob = new Xlot(temp1);
- ob.push(1);
- ob.push(100);
- ob.push(200);
- while(!ob.isEmpty())
- {
- System.out.println(""+ob.pop());
- }
- }
- }
Add Comment
Please, Sign In to add comment