codeforstartups
BAN USERpackage careerUp;
public class Stack {
private int arr[];
private int maxSize;
private int top = -1;
private int bottom = 0;
Stack(int s){
maxSize = s;
arr = new int[maxSize];
top = -1;
}
public void push(int elm){
arr[++top] = elm;
}
public int pop(){
return arr[top--];
}
public int peekArray(){
return arr[top];
}
public boolean isEmpty(){
return (top == -1);
}
public boolean isFull(){
return (top == maxSize-1);
}
public static void main(String args[]){
Stack stack = new Stack(5);
stack.push(10);
stack.push(12);
stack.push(13);
stack.push(15);
stack.push(14);
while(!stack.isEmpty()){
System.out.println(stack.pop());
}
}
}
package careerUp;
public class Stack {
private int arr[];
private int maxSize;
private int top = -1;
private int bottom = 0;
Stack(int s){
maxSize = s;
arr = new int[maxSize];
top = -1;
}
public void push(int elm){
arr[++top] = elm;
}
public int pop(){
return arr[top--];
}
public int peekArray(){
return arr[top];
}
public boolean isEmpty(){
return (top == -1);
}
public boolean isFull(){
return (top == maxSize-1);
}
public static void main(String args[]){
Stack stack = new Stack(5);
stack.push(10);
stack.push(12);
stack.push(13);
stack.push(15);
stack.push(14);
while(!stack.isEmpty()){
System.out.println(stack.pop());
}
}
}
- codeforstartups June 26, 2016