Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

created a queue using linked list #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions C++/queue using linked list
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include<iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
struct node
{
int data;
node *next;
}*front = NULL,*rear = NULL,*p = NULL,*np = NULL;
void push(int x)
{
np = new node;
np->data = x;
np->next = NULL;
if(front == NULL)
{
front = rear = np;
rear->next = NULL;
}
else
{
rear->next = np;
rear = np;
rear->next = NULL;
}
}
int remove()
{
int x;
if(front == NULL)
{
cout<<"empty queue\n";
}
else
{
p = front;
x = p->data;
front = front->next;
delete(p);
return(x);
}
}
int main()
{
int n,c = 0,x;
cout<<"Enter the number of values to be pushed into queue\n";
cin>>n;
while (c < n)
{
cout<<"Enter the value to be entered into queue\n";
cin>>x;
push(x);
c++;
}
cout<<"\n\nRemoved Values\n\n";
while(true)
{
if (front != NULL)
cout<<remove()<<endl;
else
break;
}
getch();
}