FullLessStack.java
package example.practice;
public class FullLessStack {
LinkData top=null;
public int isEmpty()
{
if(top==null)
{
return 1;
}
return -1;
}
public void push(int pushData) throws StackFullException
{
LinkData push=new LinkData();
push.setData(pushData);
push.before=top;
top.next=push;
top=push;
}
public int pop() throws StackEmptyException
{
int popData;
if(isEmpty()==1)
{
throw new StackEmptyException();
}
popData=top.getData();
top=top.before;
return popData;
}
}
class StackFullException extends Exception { }
class StackEmptyException extends Exception { }
LinkData.java
package example.practice;
class LinkData {
LinkData next,before;
int data=0;
public void setData(int input)
{
LinkData.data=input;
這邊有錯
Cannot make a static reference to the non-static field LinkData.data
}
public int getData()
{
int popData=0;
popData=LinkData.data;
這邊有錯
Cannot make a static reference to the non-static field LinkData.data
return popData;
}
}
本成是主要有想要做一個除非記憶體被吃光不然不會滿的stack
我對任何變數都沒有宣告static可是不知為啥
會出上面的錯誤訊息 請各位大大幫幫忙
或是有人對此程式能給我一些意見
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.243.14.102
→
08/24 21:18, , 1F
08/24 21:18, 1F
→
08/24 21:19, , 2F
08/24 21:19, 2F
→
08/24 21:37, , 3F
08/24 21:37, 3F
→
08/24 21:40, , 4F
08/24 21:40, 4F
→
08/24 21:46, , 5F
08/24 21:46, 5F
→
08/24 21:49, , 6F
08/24 21:49, 6F