Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.lang.Math;
- public class stac{
- public static void main(String Args[])
- {
- Scanner sc = new Scanner(System.in);
- stack_maker st = new stack_maker(5);
- st.Display();
- st.Push(1);
- st.Push(2);
- st.Display();
- System.out.println();
- }
- }
- class stack_maker {
- private int[] stack;
- private int top, size;
- stack_maker(int size)
- {
- top = -1;
- this.size = size;
- stack = new int[size];
- }
- boolean isFull()
- {
- if(top == size)
- return true;
- return false;
- }
- boolean isEmpty()
- {
- if(top == -1)
- return true;
- return false;
- }
- void Push(int n)
- {
- if(isFull())
- {
- System.out.println("Stack Overflow!");
- return;
- }
- stack[++top] = n;
- }
- void Display()
- {
- if(isEmpty())
- {
- System.out.println("Empty Stack!");
- return;
- }
- for(int i = top; i >= 0; i--)
- System.out.println(stack[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement