publicclassLinked{publicLinkednextNode;publicObjectelement;publicLinked(){nextNode=null;element=null;}publicObjectsetEle(Objectelement){ObjectoldElement=this.element;this...
public class Linked
{
public Linked nextNode;
public Object element;
public Linked()
{
nextNode = null;
element = null;
}
public Object setEle(Object element)
{
Object oldElement = this.element;
this.element = element;
return oldElement;
}
public Object getElement()
{
return element;
}
public Object setElement(Object element)
{
Object obj = this.element;
this.element = element;
return obj;
}
public Linked getNextNode()
{
return nextNode;
}
public void setNextNode(Linked nextNode)
{
this.nextNode = nextNode;
}
}
public class LinkedNode
{
public Linked top;
public int size;
public LinkedNode()
{
this.top = null;
this.size = 0;
}
public int GetSize()
{
return size;
}
public boolean isEmpty()
{
return top == null ?true:false;
}
public Object pop()
{
if(isEmpty())
{
System.out.println("");
return null;
}
Object obj = top.getElement();
top = top.getNextNode();
size--;
return obj;
}
public void push(Object element)
{
Linked temp = new Linked(element);\\这里有问题,帮忙解决下
temp.setNextNode(top);
top = temp;
size++;
}
}
public class Linkedn
{
public static void main(String[] args)
{
LinkedNode li = new LinkedNode();
li.push("1");
li.push("2");
li.push("3");
System.out.println(li.pop());
System.out.println(li.pop());
System.out.println(li.pop());
}
}
我又写了个main函数,为什么最后显示的都是null,应该在前面怎么改啊...
展开