gvsu/cs621/proj2/RationalStack.java
josh 6856920fa3 added proj2 .java files
git-svn-id: svn://anubis/gvsu@75 45c1a28c-8058-47b2-ae61-ca45b979098e
2008-03-21 20:50:52 +00:00

61 lines
1.3 KiB
Java

import java.util.Vector;
/**
* RationalStack provides a stack collection of Rational objects
*/
public class RationalStack
{
private Vector<Rational> _data = new Vector<Rational>();
/**
* pop will remove and return the Rational object from the top of the stack
* @return the Rational at the top of the stack
*/
public Rational pop()
{
int sz = _data.size();
if (sz > 0)
{
Rational r = _data.remove(sz-1);
return r;
}
return null;
}
/**
* push will add a new Rational object to the top of the stack
* @param value the Rational object to add to the stack
*/
public void push(Rational value)
{
_data.add(value);
}
/**
* isEmpty will return true if there are no Rational elements on the stack
* @return true if there are no Rational elements on the stack
*/
public boolean isEmpty()
{
return _data.isEmpty();
}
/**
* clear will remove all Rational objects from the stack
*/
public void clear()
{
_data.clear();
}
/**
* size returns the number of Rational objects in the stack
* @return the number of Rational objects in the stack
*/
public int size()
{
return _data.size();
}
}