logo

Crowdly

Browser

Add to Chrome

Baikite įgyvendinti dvikrypčio tiesinio sąrašo  metodą addNodePos() , kuris at...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Baikite įgyvendinti dvikrypčio tiesinio sąrašo metodą addNodePos(), kuris atsakingas už naujo elemento pridėjimą į nurodytą poziciją.

Dėmesio! Realizuokite tik bėgimą sąrašu nuo sąrašo pabaigos (tail) ir patį mazgo įtraukimą.

-----------------------------------------------------------------------------------------------------------------------

Kodas:

struct node

{

    int data;

    node* next;

    node* prev;

};

class DoublyLinkedList

{

private:

    node* head;

    node* tail;

    int count;

public:

    DoublyLinkedList()  //konstruktorius 

    {

        head = nullptr;

        tail = nullptr;

        count = 0;

    }

   void addNodeEnd(int value){}

   void addNodeStart(int value){}

   void addNodePos(int pos, int value)

  {

        if (pos == 1)

            addNodeStart(value);

        else if (pos == count + 1)

            addNodeEnd(value);

        else if (pos > count + 1 || pos < 1)

            std::cout << "Blogai ivesta pozicija, elementas nepridetas \n";

        else {

            if (pos <= (count / 2) + 1)

            {

                //  ŠIOS DALIES REALIZUOTI NEREIKIA

            }

            else

            {

              //  BAIGTI PILDYTI KODĄ

            }

            count++;

        }

}

More questions like this

Want instant access to all verified answers on moodle.vilniustech.lt?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome