Crazione Stack
This commit is contained in:
74
stack/FixedArrayStack.java
Normal file
74
stack/FixedArrayStack.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package stack;
|
||||
|
||||
import exceptions.EmpyStackException;
|
||||
import exceptions.FullStackException;
|
||||
|
||||
/**
|
||||
* Created with MONSTER.
|
||||
* User: xgiovio
|
||||
* Date: 05/03/14
|
||||
* Time: 0.12
|
||||
*/
|
||||
|
||||
|
||||
public class FixedArrayStack<E> extends StackRules<E> {
|
||||
|
||||
|
||||
public FixedArrayStack(){
|
||||
|
||||
stack = (E[])new Object[dcapacity];
|
||||
|
||||
}
|
||||
public FixedArrayStack( int size){
|
||||
|
||||
stack = (E[])new Object[size];
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void push(E element) throws FullStackException {
|
||||
if (isFull())
|
||||
throw new FullStackException();
|
||||
stack[++top] = element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E top() throws EmpyStackException {
|
||||
if (isEmpty())
|
||||
throw new EmpyStackException();
|
||||
return stack[top];
|
||||
}
|
||||
|
||||
@Override
|
||||
public E pop() throws EmpyStackException {
|
||||
if (isEmpty())
|
||||
throw new EmpyStackException();
|
||||
return stack[top--];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
if (size() < 1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFull() {
|
||||
if (stack.length == (top + 1))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return (++top);
|
||||
}
|
||||
|
||||
|
||||
private int top = -1;
|
||||
private int dcapacity = 100;
|
||||
private E[] stack;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user