Wednesday, June 20, 2018

Create Next Nodes Of Single Link List

#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 createlist()
{
    t=new node;
    cout<<"Enter Data in first Node: "<<endl;
    cin>>t->data;
    t->n=0;
    e=t;
    h=t;

}

void addmore()
{
    if(h==0)
    {
        cout<<"List doesn't Exist.! 1st create the list......"<<endl;
    }
    else if(h!=0)
    {

    t=new node;
    e->n=t;
    e=t;
    cout<<"Enter Data: "<<endl;
    cin>>t->data;
    e->n=0;

}
}
int main()
{
 int ch;
    label:
cout<<"======================================================================================================================="<<endl;
    cout<<"1. Create List"<<endl;
    cout<<"2. Add More Data:"<<endl;
    cout<<"3. Check Empty"<<endl;
    cin>>ch;
    if(ch==1)
    {
        createlist();
        cout<<"Data inserted Successfully"<<endl;
    goto label;
    }
    else if(ch==2)
    {
        addmore();
        goto label;
        cout<<"\n\n\n";
    }


else if(ch==3)
    {
        checkempty();
         cout<<"\n\n";
        goto label;
    }

return 0;
}




No comments:

Post a Comment