DSA Day 58/100

DSA Day 58/100

Topic: Queue

Questions Successfully Completed: 1

1) Implement Queue using Linked List

Easy

class MyQueue
{
    QueueNode front, rear;

    //Function to push an element into the queue.
    void push(int a)
    {
         QueueNode q = new QueueNode(a);
        if(front==null){
            front = rear = q;
        }
        else{
        rear.next = q;
        rear = q;
        }
    }

    //Function to pop front element from the queue.
    int pop()
    {
        if(front==null){
            return -1;
        }
        int x = front.data;
        front = front.next;
        return x;
    }
}

Thank you for reading :)