+ 1

Problems with code

#include <iostream> struct Node{ int n = 0; Node* next = nullptr; Node* prev = nullptr; }; void addNode(Node **n, Node **head, int x){ //problem starts from here if(n){ *n->next = new Node; *n->next->n = x; *n->prev = *n; *n = *n->next; std::cout << *n->n << " " << *head->*next->n; *n->next = nullptr; } else{ *n = new Node; *head = *n; *head->n = x; *head->next = nullptr; *head->prev = nullptr; std::cout << *n->n << *head->n; } } void printNode(Node *n){ if(n!=nullptr){ while(n->prev!=nullptr){ std::cout << n->n; n = n->prev; } } } int main() { Node *n = nullptr; Node *head = nullptr; addNode(&n, &head, 2); addNode(&n, &head, 4); printNode(head); return 0; } If you don't understand what it does then ask, i will answerâ˜ș

10th Oct 2018, 4:19 PM
Oleg Storm
Oleg Storm - avatar
6 Answers
+ 8
What it supposed to do? What it's doing? [Edited]: It seems you are creating LL and adding nodes. And after that printing it.
10th Oct 2018, 7:03 PM
blACk sh4d0w
blACk sh4d0w - avatar
11th Oct 2018, 9:59 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 8
Oleg Storm I am not much aware of pointer to pointer notation for passing and handling linked list. You can remove the ampersand/dereference operator (you can use only single pointer) it will work fine. You can check out these links for information: Âčhttps://stackoverflow.com/questions/3313233/linked-list-head-double-pointer-passing ÂČhttps://www.quora.com/Why-double-pointers-are-used-in-linked-list
11th Oct 2018, 11:07 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
nautaxh, yes it is a tipical node by me😆 and as you can see it always points to a nullptr, guys have already recommended me something but i gave up and want to aks for your help to complete the programme🙃 edit: it actually doesn't poit to nullptr now, so it is another problem(can be with **, as I'm new to it)
11th Oct 2018, 4:20 AM
Oleg Storm
Oleg Storm - avatar
+ 1
nautaxh, why haven't you used a pointer to pointer instead? Just curiousđŸ€”
11th Oct 2018, 10:19 AM
Oleg Storm
Oleg Storm - avatar
+ 1
to say the truth, i really enjoy learning from these forums
11th Oct 2018, 12:04 PM
Oleg Storm
Oleg Storm - avatar