Code for Program of link list using class pointers in C++ Programming
#include<iostream.h>
#include<conio.h>
class stud
{
public:
char name[20];
int rno;
class stud *next;
};
main()
{
stud *point,*first;
first=new(class stud);
point=first;
while(1)
{
clrscr();
cout<<"Please enter the name:";
cin>>point->name;
cout<<"Please enter the rollno:";
cin>>point->rno;
char ans;
while(1)
{
cout<<"\nDo you want to continue(y/n):";
cin>>ans;
if(ans=='y' || ans=='Y')
{
break;
}
elseif(ans=='n' || ans=='N')
{
break;
}
else
{
cout<<"Invalid input";
}
}
if(ans=='y' || ans=='Y')
{
point->next= new(class stud);
point=point->next;
continue;
}
else
{
point->next=NULL;
break;
}
}
point=first;
while(point!=NULL)
{
cout<<"Name is :"<<point->name<<endl;
cout<<"Rollno is :"<<point->rno<<endl;
getch();
point=point->next;
}
delete point;
delete first;
}