我有一个关于在java中实现队列的功课。我写了一段代码,但是有一个错误,我不知道如何修复它。可以请任何人帮助我吗?
这是我的代码:
public class Radha {
public int num;
public Radha pas;
public Radha(int num){
this.num = num;
}
public void shfaq(){
System.out.println(num);
}
public static void main (String [] args){
Radha x = new Radha(1);
Radhe1 r = x.new Radhe1();
r.enqueue(1);
r.shfaq();
}
class Radhe1{
public Radha koka;
public Radha bishti;
Radhe1(){
koka.pas = null;
bishti = koka;
}
public void shfaq(){
Radha theLink = koka;
while(theLink != bishti){
theLink.shfaq();
theLink = theLink.pas;
}
}
public boolean bosh(){
return(bishti == koka);
}
public int iPari (){
if (bosh())
System.out.println("radha eshte bosh");
return(koka.num);
}
public void dequeue(){
if (bosh()){
System.out.println("radha eshte bosh");
}
else{
koka = koka.pas;
}
}
public void enqueue(int a){
bishti = bishti.pas;
bishti.num = a;
bishti.pas = null;
}
}
}
答案 0 :(得分:0)
当您撰写koka.pas = null
时,您可以设置koka
pas
。你必须以某种方式初始化。