/*PROGRAM TO INSERT ELEMENTS AT THE END OF LINKED LIST*/
#include<conio.h>
#include<iostream.h>
struct node
{
int data;
struct node *link;
};
void main()
{
struct node *start=NULL,*ptr,*temp;
int num;
char ch;
clrscr();
cout<<“Inserting elements in the list:”<<endl;
do
{
temp=new node;
cout<<“Enter element: “;
cin>>num;
temp->data=num;
if(start==NULL)
{
start=temp;
start->link=NULL;
}
else
{
ptr=start;
while(ptr->link!=NULL)
{
ptr=ptr->link;
}
ptr->link=temp;
temp->link=NULL;
}
cout<<“Do you want to continue?? “;
cin>>ch;
}while(ch==’y’||ch==’Y’);
cout<<“Elements in the list are:”<<endl;
for(ptr=start;ptr!=NULL;ptr=ptr->link)
{
cout<<ptr->data<<“\t”;
}
getch();
}