public class Stack {
int stack[] = new int[100];
int top = 0;
//int ssize = 0;
public void printPop(){
System.out.println("Poppoed " + this.pop());
}
public static void main(String args[]){
Stack s = new Stack();
s.push(10);
s.push(15);
s.push(20);
s.push(25);
s.printStack();
s.printPop();
s.printPop();
s.push(19);
s.push(24);
s.printStack();
s.printPop();
s.printPop();
s.printPop();
s.printPop();
s.printStack();
}
public void push(int p){
if(top < stack.length){
stack[top++] = p;
}
//System.out.println("Top: " + top);
}
public int pop(){
int p = -99999;
if(top > 0)
p = stack[--top];
//System.out.println("Top: " + top);
return p;
}
public void printStack(){
System.out.print("Stack [LIFO order]: ");
for(int i=this.top-1; i>=0; i--){
System.out.print(stack[i] + " ");
}
System.out.println();
}
}
int stack[] = new int[100];
int top = 0;
//int ssize = 0;
public void printPop(){
System.out.println("Poppoed " + this.pop());
}
public static void main(String args[]){
Stack s = new Stack();
s.push(10);
s.push(15);
s.push(20);
s.push(25);
s.printStack();
s.printPop();
s.printPop();
s.push(19);
s.push(24);
s.printStack();
s.printPop();
s.printPop();
s.printPop();
s.printPop();
s.printStack();
}
public void push(int p){
if(top < stack.length){
stack[top++] = p;
}
//System.out.println("Top: " + top);
}
public int pop(){
int p = -99999;
if(top > 0)
p = stack[--top];
//System.out.println("Top: " + top);
return p;
}
public void printStack(){
System.out.print("Stack [LIFO order]: ");
for(int i=this.top-1; i>=0; i--){
System.out.print(stack[i] + " ");
}
System.out.println();
}
}
No comments:
Post a Comment