import java.util.LinkedList;
/*to develop my own Stack */
class MYStack {
@SuppressWarnings("unchecked")
private LinkedList list = new LinkedList();
@SuppressWarnings("unchecked")
public void pushToStack(Object obj){
list.add(obj);
}
public Object popFromStack(){
return list.removeLast();
}
public String toString(){
return list.toString();
}
}
public class Manager {
public static void main(String[] args) {
MYStack st = new MYStack();
st.pushToStack(100);
st.pushToStack(200);
st.pushToStack(30);
st.pushToStack(10);
System.out.println(st);
System.out.println(st.popFromStack());
System.out.println(st);
}
}
Hi Safiuz,
ReplyDeleteStack is having 2 functionalities called push(Obj) and pop(), if you can rename from addToStack and removeFromStack as push and pop, the program looks better
Thanks Brother
ReplyDeleteSure will take of this..