This is push function.
void push(struct node **head)
{
struct node *temp;
temp = new node;
cout<<"enter the value";
cin>>temp->data;
temp->link=NULL;
if(*head==NULL)
{
*head=new node;
*head=temp;
}
else{
temp->link=*head;
*head=temp;
}
}
this is how i am calling push.
struct node *start=NULL;
push(&start);
this is node
struct node{
int data;
struct node *link;
};
now the problem: i don't think the list is updating. The start always remains the null. Don't know why.
edit:
void display(struct node **head)
{
struct node *temp;
temp=*head;
if(*head==NULL){
cout<<"\nthe head is NULL\n";
}
while(temp!=NULL)
{
cout<<temp->data;
temp=temp->link;
}
}
int main() {
struct node *start=NULL;
push(&start);
push(&start);
push(&start);
push(&start);
push(&start);
display(&start);
return 0;
}
input:
1
2
3
4
5
now display out should have been 5 4 3 2 1 but there is some mistake.