I have a homework about implementing queues in java. I have written a code, but there is an error and I don't know how to fix it. Can please anyone help me with this?
Here is my code:
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;
}
}
}
When you write
koka.pas = null
, there is nokoka
whosepas
you can set. You must initialize that somehow.