#include <iostream>
using namespace std;
struct node
{
int a;
node *next=NULL;
void insert()
{
cout<<"\n"<<"insert a value ";
cin>>a;
}
void show()
{
cout<<"value inserted is ";
cout<<a;
}
};
Insertion is working fine(addele func is fine)
void addele(node *head)
{
node *curr = head;
node n;
while(!(curr->next==NULL))
{
curr=curr->next;
}
curr->next=&n;
n.insert();
n.show();
}
The problem is, although my code is right for the display function but I am getting infinte zeros after running the code
void display(node *head)
{
node *curr = head;
while(!(curr->next==NULL))
{
cout<<curr->a;
curr=curr->next;
}
}
int main()
{
int ch;
node n,*h;
h=&n;
while (1)
{
cout<<" 1. Add Element \n";
cout<<" 2. Display list \n";
cout<<" 3. Exit \n";
cin>>ch;
switch (ch)
{
case 1:addele(h);
break;
case 2:display(h);
break;
}
if (ch==3)
{
return 0;
}
}
return 0 ;
}