Implement queues in java

125 views Asked by At

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;

        }

    }

}
1

There are 1 answers

0
Louis Wasserman On BEST ANSWER

When you write koka.pas = null, there is no koka whose pas you can set. You must initialize that somehow.