Question: C++ Help. How to delet from shared pointer. I want to delete temp and cur. template void DoublyLinkedList ::deleteAtIndex(const unsigned int index) { if (front

C++ Help. How to delet from shared pointer. I want to delete temp and cur.C++ Help. How to delet from shared pointer. I want to delete

template

void DoublyLinkedList::deleteAtIndex(const unsigned int index)

{

if (front == nullptr)

{

cout

return;

}

if (index > count)

{

cout

return;

}

if (index == 0)

{

shared_ptr> temp(front);

front = front->forward;

delete temp;

if (count == 0)

{

front = nullptr;

back = nullptr;

count--;

return;

}

count--;

return;

}

if (index == count-1)

{

shared_ptr> temp(nullptr);

shared_ptr> cur(front);

int tracker = 0;

while (tracker

{

temp = cur;

cur = cur->forward;

tracker++;

}

delete cur;

back = temp;

back->backward = nullptr;

count--;

return;

}

shared_ptr> temp(nullptr);

shared_ptr> cur(front);

int tracker = 0;

while (tracker

{

temp = cur;

cur = cur->forward;

tracker++;

}

temp->forward = cur->forward;

delete cur;

count--;

}

delete icrp frontullptri back-ackward nullptr

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!