Hi, guys code for queue using link list in c++ language
#include<iostream>
using namespace std;
struct node
{
int data;
node *next;
};
struct node *front=0, *rear=0;
void enqueue(int x)
{
node *newnode;
newnode=new node;
newnode->next=0;
newnode->data=x;
if(front==0 and rear==0)
{
front=rear=newnode;
}
else
{
rear->next=newnode;
rear=newnode;
}
}
void display () {
node *temp=front;
while(temp!=0)
{
cout<<temp->data<<endl;
temp=temp->next;
}
}
void dequeue() {
node *temp=front;
front=front->next;
delete (temp) ;
}
main() {
enqueue(3) ;
enqueue (8) ;
enqueue(7) ;
dequeue () ;
display () ;
}
Comments
Post a Comment