#include <iostream>
using namespace std;
struct node
{
int data;
node *n;
};
struct node *h,*e,*t;
void checkempty()
{
if(h==0)
{
cout<<"List is empty..."<<endl;
}
else
{
cout<<"List is not empty"<<endl;
}
}
void create1stnode()
{
t=new node;
cout<<"Enter Data:"<<endl;
cin>>t->data;// if we enter 8
t->n=0;
e=t;//because here our first and last node is t....
h=t;
}
void addmore()
{
if(h==0)
{
cout<<"List doesn't exist..1st create the list"<<endl;
}
else
{
t=new node;
cout<<"Enter Data:"<<endl;
cin>>t->data;// if we enter 10...
e->n=t;
e=t;
e->n=0;
}
}
void printlist()
{
if(h==0)
{
cout<<"List is Empty"<<endl;
}//To check is list empty or not.....
else if(h!=0)
{
for(t=h; t!=0; t=t->n)
{
cout<<t->data<<endl;
}
}
}
int main()
{
int ch;
label:
cout<<"======================================================================================================================="<<endl;
cout<<"1. Create List"<<endl;
cout<<"2. Add More Data:"<<endl;
cout<<"3. Check List is Empty or Not!"<<endl;
cout<<"4. Print List"<<endl;
cin>>ch;
if(ch==1)
{
create1stnode();
cout<<"Data inserted Successfully"<<endl;
goto label;
}
else if(ch==2)
{
addmore();
goto label;
cout<<"\n\n\n";
}
else if(ch==3)
{
checkempty();
goto label;
}
else if(ch==4)
{
printlist();
goto label;
}
return 0;
}
using namespace std;
struct node
{
int data;
node *n;
};
struct node *h,*e,*t;
void checkempty()
{
if(h==0)
{
cout<<"List is empty..."<<endl;
}
else
{
cout<<"List is not empty"<<endl;
}
}
void create1stnode()
{
t=new node;
cout<<"Enter Data:"<<endl;
cin>>t->data;// if we enter 8
t->n=0;
e=t;//because here our first and last node is t....
h=t;
}
void addmore()
{
if(h==0)
{
cout<<"List doesn't exist..1st create the list"<<endl;
}
else
{
t=new node;
cout<<"Enter Data:"<<endl;
cin>>t->data;// if we enter 10...
e->n=t;
e=t;
e->n=0;
}
}
void printlist()
{
if(h==0)
{
cout<<"List is Empty"<<endl;
}//To check is list empty or not.....
else if(h!=0)
{
for(t=h; t!=0; t=t->n)
{
cout<<t->data<<endl;
}
}
}
int main()
{
int ch;
label:
cout<<"======================================================================================================================="<<endl;
cout<<"1. Create List"<<endl;
cout<<"2. Add More Data:"<<endl;
cout<<"3. Check List is Empty or Not!"<<endl;
cout<<"4. Print List"<<endl;
cin>>ch;
if(ch==1)
{
create1stnode();
cout<<"Data inserted Successfully"<<endl;
goto label;
}
else if(ch==2)
{
addmore();
goto label;
cout<<"\n\n\n";
}
else if(ch==3)
{
checkempty();
goto label;
}
else if(ch==4)
{
printlist();
goto label;
}
return 0;
}