Vote count:
0
My insert-in-front and insert-at-the-end are working just fine. I wrote those in 2 separated functions, it's the insert-in-middle that I'm having a bit of a hard time to wrap my mind around for some reason... The last else statement is where I'm currently working on, it works, but it doesn't work the way I want it to or it's supposed to. If someone can explain it to me where I did wrong and what I need to do, I'd really appreciate it.
void add(int n, T d) {
node<T> *tptr = new node<T>(d);
if(n > size()) {
return;
}
if(n == 0) {
add_first(d);
} else if(n == size()) {
add_last(d);
} else {
**node<T> *newptr = new node<T>(d);
tptr = head;
newptr->prev = tptr;
newptr->next = tptr->next;
newptr->next->prev = newptr;
tptr->next = newptr;**
}
};
asked 31 secs ago
how to insert middle of doubly linked list
Aucun commentaire:
Enregistrer un commentaire