Sunteți pe pagina 1din 3

#include<iostream.

h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
struct student
{
int Rno;
char name[20];
student *prev;
student *next;
};
void makelist(student *sptr);
void insert(student *sptr);
void traverse(student *sptr);
void Del(student *sptr);
void search(student *sptr);
void Start(student *strt);
void main()
{
clrscr();
student *strt;
char a='y';
strt=new student;
cout<<"\t\t\t\tMy name is Turbo Link List"<<endl;
cout<<"\t\tI can do several things but First we shall enter Data"<<endl;
makelist(strt);
cout<<"Thanks for inserting data"<<endl;
while(a=='y')
{
Start(strt);
cout<<"Would you like To Do Somthing else Y/N";
cin>>a;
}
getch();
}
void Start(student *strt)
{
clrscr();
cout<<"Select\n1.traverse\n2.search\n3.Insert\n4.Deletion"<<endl;
int n;
cin>>n;
switch(n)
{
case 1:
traverse(strt);
break;
case 2:
search(strt);
break;
case 3:
insert(strt);
break;
case 4:
Del(strt);
break;
default:
cout<<"Wrong Number inserted";
}
}
void makelist(student *sptr)
{
sptr->prev=0;
char what='y';
while(what=='y')
{
cout<<"Enter the name of student ";
gets(sptr->name);
cout<<"Enter the Roll number of Student ";
cin>>sptr->Rno;
sptr->next=0;
cout<<"Do you have more students to register Y/N";
cin>>what;
if(what=='y')
{
sptr->next=new student;
sptr->next->prev=sptr;
sptr=sptr->next;
}
}
}
void traverse(student *sptr)
{
char cond,P;
clrscr();
cout<<"Write R for only Roll numbers and N for Names too ";
cin>>cond;
while(sptr!=0)
{
cout<<sptr->name<<endl;
if(cond=='n')
{
cout<<" Roll number "<<sptr->Rno<<endl;
}
cout<<"Do you want to traverse 'N'ext or 'P'revious ";
cin>>P;
if(P=='p')
sptr=sptr->prev;
else
sptr=sptr->next;
getch();
}
cout<<endl;
}
void search(student *sptr)
{
int Rno,chk; chk=-1;
cout<<"Please Enter the Roll number to be search";
cin>>Rno;
clrscr();
cout<<"We are about to search..."<<Rno;
sound(440);
delay(800);
while(sptr!=0)
{
if(sptr->Rno==Rno)
{
cout<<"Founded...Founded...Founded\n";
cout<<sptr->Rno<<" "<<sptr->name;
chk++;
}
sptr=sptr->next;
}
if(chk==-1)
cout<<"Not Found";
}
void insert(student *sptr)
{
student item;int position;
cout<<"Enter the Roll number Name Position to be inserted "<<endl;
cin>>item.Rno>>item.name>>position;
int point=1;
student *ptr;
ptr=&item;
while(point<=position)
{
if(point==position-1)
{
ptr->next=sptr->next;
ptr=sptr->next;
}
sptr=sptr->next;
point++;
}
}
void Del(student *sptr)
{
int position,point=1;
cout<<"Enter the position to be Deleted";
cin>>position;
student *ptr;
while(point<=position)
{
if(point==position)
{
ptr->next=sptr->next;
}
ptr=sptr;
sptr=sptr->next;
}
}

S-ar putea să vă placă și