Bubble Sort
Bubble Sort
Bubble Sort
ASSIGNMENT NO 1
CLASS : BSCS 3
ROLL NO : 222201017
#include<string>
#include<conio.h>
struct node{
node* next;
node* prev;
int id;
string name;
};
class course{
node* head;
node* tail;
public:
course(){
head=NULL;
tail=NULL;
}
n->id=data;
n->name=nam;
if(head==NULL){
head=n;
tail=n;
tail->next=head;
return;
n->next=head;
head->prev=n;
head=n;
tail->next=n;
n->prev=tail;
void display(){
node* temp=head;
do{
cout<<"course id = "<<temp->id<<endl;
temp=temp->next;
while(temp!=head);
cout<<endl;
void reverse(){
node* temp=tail;
do{
cout<<"course id = "<<temp->id<<endl;
temp=temp->prev;
while(temp!=tail);
cout<<endl;
}
n->id=data;
n->name=nam;
if(head==NULL){
head=n;
tail=n;
tail->next=head;
head->prev=tail;
return;
tail->next=n;
n->prev=tail;
tail=n;
n->next=head;
head->prev=n;
}
void deleteathead(){
node* temp=head;
head=head->next;
tail->next=head;
head->prev=tail;
void deleteattail(){
node* temp=tail;
tail=tail->prev;
tail->next=head;
head->prev=tail;
int resize(){
node* temp=head;
int size=1;
do{
temp=temp->next;
size++;
}while(temp->next!=head);
return size;
node* temp=head;
int size=1;
do{
if(index==size){
cout<<"course id="<<temp->id<<endl;
cout<<"course name="<<temp->name<<endl;
return;
temp=temp->next;
size++;
}while(temp!=head);
cout<<"invalid index\n";
return false;
node* temp=head;
do{
if(d==temp->id){
return true;
temp=temp->next;
}while(temp!=head);
return false;
};
int main(){
course s;
int ch;
int i;
string n;
jo:
cout<<"Enter 8 to exit\n";
cin>>ch;
switch(ch){
case 1:
cin>>i;
cin>>n;
if(s.check(i)){
cout<<"already exist\n";
}
else{
s.insertathead(i,n);
cout<<"Course is added\n";
goto jo;
break;
case 2:
cin>>i;
cin>>n;
if(s.check(i)){
cout<<"already exist\n";
else{
s.insertattail(i,n);
cout<<"Course is added\n";
goto jo;
break;
case 3:
s.deleteathead();
cout<<"Course is deleted\n";
goto jo;
break;
case 4:
s.deleteattail();
cout<<"Course is deleted\n";
goto jo;
break;
case 5:
goto jo;
break;
case 6:
cout<<"Enter index:";
cin>>i;
s.retrive(i);
goto jo;
break;
case 7:
s.display();
goto jo;
break;
case 8:
exit(0);
break;
default:
cout<<"Invalid\n";
goto jo;
break;
OUTPUT: