Trying to work out Linked list problems. Stuck up with this basic mistake Head value is not "NULL" in createLinkList(). What trick I am missing here . Here is my code.
#include <iostream>
using namespace std;
void createLinkList(struct node**);
void showList();
void insertNode();
struct node{
int data;
struct node * next;
};
int main()
{
struct node* head = NULL;
createLinkList(&head);
cout<<"inside main function \t"<<head<<endl;
return 0;
}
void createLinkList(struct node **head){
int data;
struct node * new_node;
cout<<"creating Link List ..."<<endl;
cout<< "Enter the data to be inserted"<<endl;
cin >> data;
cout<<"inside createLinkList \t"<<head<<endl;
if (head == NULL){
new_node->data=data;
new_node->next=*head;
*head=new_node;
cout<<"Element Added at Head Position"<<endl;
}
else{
cout<<"Element added at other positions"<<endl;
}
}
cannot understand why head value is different in main() and createLinkList().