- #1
needOfHelpCMath
- 72
- 0
how would be able to delete the middle D: so far I deleted the last two, which i do not want.
These are my values in the nodes: 9->1->2->4->10->6->8
These are my values in the nodes: 9->1->2->4->10->6->8
HTML:
//part F will tranverse in the middle and delete the middle
void insertMiddle(Node *nn) {
while(nn->next->next->next != NULL) {
nn = nn->next;
}
delete nn->next;
nn->next = NULL;
}
int main() {
// part A
Node *a;
a = new Node(1,NULL);
Node *b;
b = new Node(2,NULL);
Node *c;
c = new Node(4,NULL);
Node *d;
d = new Node(6,NULL);
Node *e;
e = new Node(8,NULL);
Node *f;
f = new Node(9,NULL); // insert at the beginning of Node *a;
Node *g;
g = new Node(10,NULL); // insert in the middle
f->next = a;
a->next = b;
b->next = c;
c->next = d;
d->next = e;
c->next = g;
g->next = d;
/ /part F
list.insertMiddle(f);
cout << endl;
list.print(f);
return 0;
}