java

  flaz1984 12:30 20 Nov 03
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.

How to get Windows 10 for free | How to install Windows 10: There is still a way to avoid paying…

1995-2015: How technology has changed the world in 20 years

Alex Chinneck’s giant ice cube Christmas tree at Kings Cross

Apple rumours & predictions 2017: The iPhone 8, new iPads, and everything else you should expect fr7…