Queue Program In C++ In Hindi

C++

Queue Program In C++ In Hindi – Is Post Me Ham C++ Queue Program Ko Dekhne Wale Hai |

Also Read – Become A Web Developer In Hindi

What Is Queue Logic In Hindi – Queue Program Me 3 Operation Hote Hai Insertion And Deletion And Display, Isme Ham Insertion Karte Time Last Me Element Add Karte Hai And Deletion Karte Time Ham First Element Delete Karte Hai, Ise Hi Queue Program Kahte Hai Waise Ye Jyada time Interview Me Question Ask Kiya Jata Hai |

Queue Program In C++ In Hindi

C++ Me Ham is Program Ko Banane Ke Liye Ek Class Queue Create Karenge And Fir Ham Class Ke Under Hi Ye [ insert(); del(); display();] 3 Function Define Karenge Or Fir Inhe Operator Overloading :: Ki Help Inhe Access Karke Inke Program Ko Ham Likhenge |

Example:

#include<iostream>
using namespace std;
const int size=5;
class Queue
{ 
	public:
	int q[size],front,rear,x,result;
	void insert();
	void del();
	void display();
	Queue()
		{ 
			front=0;
			rear=0;
		}
};

void Queue::insert()
{ 
	cout<<rear<<endl;
	if(rear>=size)
		cout<<"\n Queue overflow! \n";
	else
	{ 
		cout<<"\n Enter the number to be inserted:";
		cin>>x;
		rear++;
		q[rear]=x;
		cout<<"\n Number pushed in the queue:"<<q[rear];
	}
}

void Queue::del()
{ 
	if(rear==0)
		cout<<"\n Queue underflow! \n";
	else
	{ 
		if(front==rear)
		{ 
			front=0;
			rear=0; 
		}
		else
			front++;
	}
	cout<<"\n Deleted elements is:";
	result=q[front];
	cout<<result;
}

void Queue::display()
{ 
	if(rear==0)
		cout<<"\n Queue underflow! \n";
	else
		cout<<"\n Contents of queue is:";
		for(int i=front+1;i<=rear;i++)
		{
			cout<<q[i]<<"\t";
		}
}

int main()
{ 
	int c;
	Queue qu;
	do
	{ 
		cout<<"\n 1. Insertion \n 2. Deletion \n 3. Display \n ";
		cout<<"\n Enter your choice:";
		cin>>c;
		switch(c)
		{ 
			case 1:
				qu.insert();
				break;
			case 2:
				qu.del();
				break;
			case 3:
				qu.display();
				break;
			default:
				cout<<endl<<"Invalid choice."<<endl;
		}
	}while(c<4);
return 0;
}

Output:

1. Insertion
2. Deletion
3. Display
Enter your choice:1
Enter the number to be inserted:10
Number pushed in the queue:10
1. Insertion
2. Deletion
3. Display
Enter your choice:1
Enter the number to be inserted:20
Number pushed in the queue:20
1. Insertion
2. Deletion
3. Display
Enter your choice:3
Contents of the queue is:10 20
1. Insertion
2. Deletion
3. Display
Enter your choice:2
Deleted elements is:10
1. Insertion
2. Deletion
3. Display
Enter your choice:2
Deleted elements is:20

Aap Upper Output Ko Dekh Kar Program Ko Understand Kar Sakte Hai, isme Hamne Class Queue Create Karke And Fir Unke Value Ko Input Karaya Hai, Uske Bad Hame Unhe Print Kar Diya Hai WIth Amount Ke Sath |

Leave a Reply

Your email address will not be published. Required fields are marked *