Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Esc NODE \'back; public: -PQueueLinkedList()XdestroyListo:) void enqueue(NODE \"

ID: 3601844 • Letter: E

Question

Esc NODE 'back; public: -PQueueLinkedList()XdestroyListo:) void enqueue(NODE ") pqueueLinkedList(tront- NULL;back NULL) NODE' dequeue(l): void destroyList): void PQueueLinkedList:enqueue(NODE 'n) IflfrontNULL) liqueue has one node. front n back-n elsellqueue has more than one node #1 f( n-data.id> temp->data.id) New node id's is greater than all others. n>N front; front n else IrSearch for the position for the new node. whilel n->data.id data.id) if(temp->N == NULL) break; temp temp>N; I/New node id's smallest than all others iftemp->N NULL&& n>data.id data.id) #2 back n; else WNew node id's is in the medium range. temp>P>N n n-P temp->P; temp->P n; NODE PQueueLinkedList::dequeue0 NODE 'temp; if( backNULL) IIno nodes else if(back->P = NULL) /there is only one node return NULL;

Explanation / Answer

class PQueueLinkedList{
    Node *back,*front;
    public:
    PQueueLinkedList(){
        front = NULL;
        back = NULL;
    }

    ~PQueueLinkedList(){
        destroyList();
    }
    void enqueue(Node *);
    Node *dequeue();
    void destroyList();
};

void PQueueLinkedList::enqueue(Node *n)
{
    if(front==NULL)
    {
        front = n;
        back = n;
    }
    else
    {
        back = back+1;
        back = n;
        if(n->data.id>temp->data.id)
        {
            front->P = n;
            n->N = front;
            front = n;
        }
        else
        {
            while(n->data.id>temp->data.id)
            {
                if(temp->N == NULL)
                    break;
                temp = temp->N;
            }
            if(temp->N == NULL && n->data.id < temp->data.id)
            {
                back->N = n;
                n->P = back;
                back = n;
            }
            else
            {
                temp->P->N = n;
                n->P = temp->P;
                n->N = temp;
                temp->P = n;
            }
        }
    }
}

Node* PQueueLinkedList::dequeue()
{
    Node *temp;
    if(back == NULL)
        return NULL;
    else if(back->P == NULL)
        return back;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote