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

OnePlus 5 review

Alice Saey's mesmerising animation for Dutch singer Mark Lotterman

iPad Pro 10.5in (2017) review

Comment booster votre iPhone ?