Linked list c++ | Sololearn: Learn to code for FREE!

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

9/17/2021 2:00:07 PM

Gajendra Sonare

3 Answers

New Answer

+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 .

+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

+1

Why are you even implementing a linked list in C++ when the C++ standard library already has the list and forward_list classes? http://www.cplusplus.com/reference/list/list/ http://www.cplusplus.com/reference/forward_list/forward_list/ Your linked list will only handle int values whereas the lists in the Standard Template Library (STL) can handle data of any type.