Respuesta :
Answer:
#include<iostream>
#include<stdio.h>
using namespace std;
class Node
{
public:
string name;
int waittime;
Node *next;
Node(string n,int w)
{
name=n;
waittime=w;
next=NULL;
}
};
Node *insert(Node *head,string name,int waittime)
{
Node *temp=new Node(name,waittime);
if(head==NULL||head->waittime>waittime)
{
temp->next=head;
head=temp;
}
else
{
Node *p=head;
while(p->next!=NULL)
{
if(p->next->waittime>waittime)
{
temp->next=p->next;
p->next=temp;
break;
}
p=p->next;
}
if(p->next==NULL)
{
p->next=temp;
}
}
return head;
}
Node *remove(Node *head)
{
if(head==NULL)
return NULL;
string name=head->name;
int waittime=head->waittime;
cout<<name<<" with wait time "<<waittime<<" landed"<<endl;
head=head->next;
return head;
}
void print(Node *head)
{
if(head==NULL)
return;
Node *temp=head;
cout<<"All the landing requests: "<<endl;
while(temp!=NULL)
{
cout<<temp->name<<" with waiting time "<<temp->waittime<<endl;
temp=temp->next;
}
}
int main()
{
Node *head=NULL;
cout<<" Welcome to plane landing system\n"<<endl;
int exit=0;
while(1)
{
cout<<"1. Make a landing request"<<endl;
cout<<"2. Land a plane"<<endl;
cout<<"3. List all the landing requests"<<endl;
cout<<"4. Exit\n"<<endl;
cout<<"Select your option: ";
int i;
cin>>i;
string name;
int waittime;
switch(i)
{
case 1:
cout<<"Enter plane name: ";
cin>>name;
cout<<"Enter wait time before landing: ";
cin>>waittime;
head=insert(head,name,waittime);
cout<<"Landing request made"<<endl;
break;
case 2:
head=remove(head);
break;
case 3:
print(head);
break;
case 4:
exit=1;
break;
default:
cout<<"Invalid option...Try again"<<endl;
break;
}
if(exit==1)
break;
}
return 0;
}
Explanation:
Input the code and see the output.