Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  ahmed.cpp
Language: C/C++
Code:
#include<iostream>
#include<conio.h>
#include<process.h>
struct node
{int data;
 node*link;
};
node*add_Q(node*first)
{
    node*temp;
temp=new node;
cin>>temp->data;
temp->link=NULL;
if(rear!=NULL)
rear->link=temp;
else
{
rear=temp;
}
return rear;
}
node*del_Q(node*first)
{
    node*temp;
if(front==NULL)
cout<<"list is emptyn";
else
{
    temp=front;
    front=front->link;
    temp->link=NULL;
    delete temp;
    }
    return first;
}

void show_Q(node*first)
{node*temp;
if(front==NULL)
cout<<"list is emptyn";
else
{temp=front;
while(temp!=NULL)
cout<<'n'<<temp->data;
temp=tem->link;
}
}
 void main()
 node*first,*rear;
 front=rear=NULL;
 int ch,n;char ch1;
 do{
     cout<<"menu'n";
     cout<<"1.add_Qn";
     cout<<"2.del_Qn";
     cout<<"3.show_Qn";
     cout<<"4.exitn";
     cout<<"enter your choicen";
     cin>>ch;
     switch(ch)
     case 1:
     rear=add_Q(rear)
     if(front==NULL)
     front=rear;
     break;
     case 2:
     front=del_Q(front)
     if(front==NULL)
     rear=front;
     break;
     case 3:
     front=show_Q(front)
     break;
     case 4:
     exit;
 }
 cout<<"do you want to continue?n";
 cin>>ch;
 }
 while(ch1=='y'||ch1=='Y');
 getch();
 }
 }
}
          
          
Comments: