Tuesday, 3 February 2015

Queues Data Structure in C++

Structure of the Problem Requirements 

The queue data structure follow the FIFO rule which is the abbreviation of first in first out. The Queue is the example of the linear data structure and it has large usage in computer science , electronic devices and in transport. In this problem we just make a queue and then apply its function on different values.

Source Code

 #include <iostream>
 #include <windows.h>
using namespace std;
class linkedlist
{
  private:
struct node
{
int value;
node *next;
};
node *front;
node *rear;
int item;

 public:
linkedlist()
{
front=NULL;
rear=NULL;
}
void enqueue(int num)
{
node *newnode;
newnode = new node;
newnode->value= num;
newnode->next=NULL;
if(front==NULL && rear == NULL)
{
front = newnode;
rear = newnode;
}
else
{
rear->next=newnode;
rear= newnode;
}
}
void deqeue()
{
node *newnode;
newnode= front;
front=front->next;
delete newnode;
}

void display()
{
node *result;
result = front;
while(result!=NULL)
{
cout<<result->value<<endl;
result= result-> next;
}  
}
}; // end of class
int main()
{

linkedlist l;
cout<<"Before DeQuoue we have these Numbers \n\n";
l.enqueue(2);
l.enqueue(3);
l.enqueue(4);
l.enqueue(5);
l.enqueue(6);
l.display();
cout<<"after deque we have the following values"<<endl;
l.deqeue();
l.display();
system("pause");
}

Output of the Program

Queues Data Structure in C++

Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment