0% found this document useful (0 votes)
12 views6 pages

Double A,$j&r

Uploaded by

Reis Dura
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

Double A,$j&r

Uploaded by

Reis Dura
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include <iostream>

#include<iomanip>

using namespace std;

struct student

{ int id;

string name;

struct student *perv;

struct student *next;

};

struct student *head=NULL;struct student *temp=(new student);

void insertfirst()

struct student *temp,*temp1;

temp=new student;cout<<"enter id:";cin>>temp->id;

cout <<" enter Name: "<<endl;

cin>>temp->name;

temp->next=NULL;

temp->perv=NULL;

if(head==NULL)

head=temp;

else

temp1=head;
head=temp;

temp->next=temp1;

temp1->perv=temp;

}void insert_atmid(int position)

{struct student *temp=new student;

cout <<"Name: "<<endl;

cin>>temp->name;

temp->next=NULL;

temp->perv=NULL;

if(head==NULL) head=temp;

else { while(temp->next!=NULL)

{temp=temp->next;

}temp->next=(new student);

(new student)->perv=temp;

(new student)->next=NULL;}

void insertend()

struct student *temp,*last;

temp=new student;

cout <<"Name: "<<endl;

cin>>temp->name;
temp->next=NULL;

temp->perv=NULL;

if(head==NULL)

head=temp;

last=temp;

else

last->next=temp;

temp->next=last;

last=temp;

void delete_first()

struct student *temp,*temp1;

if(head == NULL)

cout<<"Nothing in the list"<<endl;

else

temp=head;

head=temp->next;
delete(temp);

void delete_end()

struct student *temp,*temp1;

if(head == NULL)

cout<<"Nothing to delete in the list"<<endl;

else

temp=head;

while(temp->next!= NULL)

temp1=temp;

temp=temp->next;

delete(temp);

temp1->next=NULL;

void display()

{
struct student *temp=head;

if(head == NULL)

cout<<"Empty list"<<endl;

else{

cout<<"===============================================================================
======="<<endl;

cout<<setw(10)<<"Name"<<endl;

cout<<"===============================================================================
======="<<endl;

while(temp != NULL)

cout<<setw(10)<<temp->name<<endl;

temp=temp->next;

int main(int argc, char** argv) {

int choice;

int repeat=0;struct student stud1;

do

cout<<"Enter your ch{}oice"<<endl;


cout<<"1.insert at the first"<<endl;

cout<<"2.insert at the end"<<endl;

cout<<"3. insert at the mid"<<endl;

cout<<"4.Delete at the first"<<endl;

cout<<"5.Delete at the end"<<endl;

cout<<"6.Display"<<endl;

cout<<".Exit"<<endl;

cin>>choice;

switch(choice)

case 1:insertfirst();break;

case 2:insertend();break;

case 3:insert_atmid(2);break;

case 4:delete_first();break;

case 5:delete_end();break;

case 6:display();break;

case 7:repeat=1;break;

default:cout<<"Wrong Choice"<<endl;

}while(repeat==0);

return 0;}

You might also like