package pila;
import java.util.*;
interface IPila{
public boolean llena();
public boolean vacia();
public void push(int elem);
public int pop();
}
class Pila implements IPila {
int tope=-1;
private int [] pila = new int [10];
final int MAX = 9;
public boolean llena (){
return (tope==MAX);
}
public void push (int elem){
if(this.llena()) then
//ERROR
else{
tope ++;
pila[tope]=elem;
}
}
public boolean vacia(){
return(tope==-1);
}
public int pop(){
if(this.vacia())then
//ERROR
else{
int x=pila[tope];
tope --;
return x;
}
}
}
package pila;
import java.util.Vector;
/**
*
* @author MarAnn
*/
public class Stack {
private Vector items;
public Stack(){
items = new Vector(10);
}
public Object push(Object item){
item.addElement(item);
return item;
}
public synchronized Object pop(){
int len = items.size();
Object obj = null;
if(len == 0) throw new EmptryStackException();
obj = items.elementAt(len-1);
items.removeElementAt(len-1);
return obj;
}
public boolean isEmpty(){
if(items.size == 0) return true;
else return false;
}
}
interface IPila {
public boolean llena();
public boolean vacia();
public void push(int elem);
public int pop();
}
class Pila implements IPila {
int tope = -1;
private int[] pila = new int[10];
final int MAX = 9;
public boolean llena() {
return (tope == MAX);
}
public void push(int elem) {
if (this.llena()) {
// ERROR
} else {
tope++;
pila[tope] = elem;
}
}
public boolean vacia() {
return (tope == -1);
}
public int pop() {
if (this.vacia()) {
// ERROR
// Aqui debes retornar algo!
return 0;
} else {
int x = pila[tope];
tope--;
return x;
}
}
}
import java.util.EmptyStackException;
import java.util.Vector;
public class Stack {
private Vector items;
public Stack() {
items = new Vector(10);
}
public Object push(Object item) {
items.addElement(item);
return item;
}
public synchronized Object pop() {
int len = items.size();
Object obj = null;
if (len == 0)
throw new EmptyStackException();
obj = items.elementAt(len - 1);
items.removeElementAt(len - 1);
return obj;
}
public boolean isEmpty() {
if (items.size() == 0)
return true;
else
return false;
}
}