0
Why am I getting 2,3,4,0 as output i just need 2,3,4 please check my code guys i need help
#include <iostream> using namespace std; class Node{ public: int data; Node *next; }; void insertAtFirst(Node **head_ref, int data){ Node * new_node = new Node(); new_node->data = data; new_node->next = (*head_ref); (*head_ref) = new_node; } void printList(Node *trav){ while(trav!=NULL){ cout<<trav->data<<" "; trav = trav->next; } } int main(){ Node *head = new Node(); insertAtFirst(&head, 4); insertAtFirst(&head, 3); insertAtFirst(&head, 2); printList(head); }
2 ответов
+ 2
Martin Taylor thank you so much
I wrote Node *head = NULL;
And my problem is solved and thanks for your suggestion to