Linked list c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Linked list c++

Can some help me to traverse the current list and remove error and warnings from this code. https://code.sololearn.com/czsvFDPwhqNM

17th Sep 2021, 2:00 PM
Gajendra Sonare
Gajendra Sonare - avatar
2 Answers
+ 3
Correct code, void insertion(struct Node *node,int data){ if(node->next==NULL and node->data != 0){ Node *temp = new Node(); temp->data = data; node->next = temp; }else if(node->next == 0 and node->data == 0 ){ node->data = data; } } void traverse(struct Node *head){ while(head){ cout<<head->data; head = head->next; }; } to get rid of warning i replaced NULL with 0 .
17th Sep 2021, 2:28 PM
Abhay
Abhay - avatar
+ 1
these are some of the mistakes you are making. struct Node{ int data; Node *next; }; void insertion(Node *node, int data){ void traverse(Node *head){ if(node->next == NULL && node->data != 0) { } else if(node->next == 0 && node->data == 0 ){ https://www.cprogramming.com/tutorial/lesson15.html Keep learning & happy coding :D
17th Sep 2021, 4:29 PM
SoloProg
SoloProg - avatar