java

  flaz1984 12:30 20 Nov 2003
Locked

hi
i hav wrote the following piece of code, however i need to convert it to a symbol stack ( for char's). Does any one no what needs changed as im a little stuck






public class ArrayStack {
private Object[] elems;
private int depth;
/////////////// Constructor ///////////////
public ArrayStack (int maxDepth) {
elems = new Object[maxDepth];
depth = 0;
}
/////////////// Accessors ///////////////
public boolean isEmpty () {
return (depth == 0);
}
public Object getLast () {
return elems[depth-1];
}
public String toString(){
String outString = "Contents of stack \n";
for (int i = 0; i depth; i++)
outString = outString + elems[i]+ "\n";
return outString;
}

/////////////// Transformers ///////////////
public void clear () {
for (int i = 0; i depth; i++)
elems[i] = null;
depth = 0;
}
public void push (Object elem) {
elems[depth++] = elem;
}
public Object pop () {
Object topElem = elems[--depth];
elems[depth] = null;
return topElem;
}
}

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

iMac Pro review

25 book design and illustration tips

iMac Pro review

Idées cadeaux pour geeks et tech addicts