0% found this document useful (0 votes)
15 views3 pages

Queue Management Program in C++

The document is a C++ program that implements a queue data structure with basic operations such as enqueue, dequeue, checking if the queue is empty or full, and displaying the current queue. It provides a menu-driven interface for user interaction to perform these operations. The program utilizes an array to store the queue elements and manages the front and rear indices accordingly.

Uploaded by

huydorov001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Queue Management Program in C++

The document is a C++ program that implements a queue data structure with basic operations such as enqueue, dequeue, checking if the queue is empty or full, and displaying the current queue. It provides a menu-driven interface for user interaction to perform these operations. The program utilizes an array to store the queue elements and manages the front and rear indices accordingly.

Uploaded by

huydorov001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// Ngăn_Đợ[Link] : This file contains the 'main' function.

Program execution begins


and ends there.
//

#include <iostream>
using namespace std;
int sz;
int front = -1; // vị trí ở đầu
int rear = -1; // vị trí sau
int Q[100]; //Q[sz]
void enqueue(int value); // Them phan tu vào cuoi
void dequeue();
bool empty(); //Kiem tra stack có rỗng không
bool full(); // Kiểm tra đã full chưa
void display();
int val_front();
int main()
{
int choice, val;
cout << "Nhap sz cua Stack : ";
cin >> sz;

while (1) {
cout << "-------------" << endl;
cout << "*** Menu *** \n [Link] Chuong trinh \n [Link] phan tu vao
stack \n [Link] phan tu o dau Stack \n [Link] thi gia tri dau tien trong Queue \n
[Link] thi stack hien tai \n [Link] tra queue full \n [Link] tra queue rong " <<
endl;
cout << "-------------" << endl;
cout << "Nhap lua chon cua ban : ";
cin >> choice;
switch (choice) {
case 0:
return 0;
case 1:
cout << "Nhap gia tri muon them vao Queue : ";
cin >> val;
enqueue(val);
break;
case 2:
dequeue();

break;
case 3:
cout << val_front();
break;
case 4:
display();
break;
case 5:
if (full()) {
cout << "Queue hien da full khong the them phan tu ";
}
else {
cout << "Queue hien chua full co the them phan tu ";
}break;
case 6 :
if (empty()) {
cout << "Queue hien rong ";
}
else {
cout << "Queue khong rong ";
}break;
}cout << endl;

}
void enqueue(int val) {
if (full()) {
cout << "Hang doi da day khong the them phan tu ";
}
else {
front = 0;
rear++;
Q[rear] = val;
}
}
bool full() {
if (rear == sz-1) {
return true;
}
else {
return false;
}
}
void dequeue() {
if (empty()) {
cout << "Ham da rong khong con phan tu de xoa";
}
else {
cout << "Da xoa phan tu ơ dau ";
for (int i = 0; i < rear;i++) {
Q[i] = Q[i + 1];
}rear--;
}
}
bool empty() {
if (front == rear && front == -1) {
return true;
}
else {
return false;
}
}
int val_front() {
if (empty()) {
cout << "Ham rong khong co phan tu o dau de hien thi ";
}
else {
int giatri = Q[0];
return giatri;
}
}
void display() {
cout << "Queue hien tai cua ban la : ";
for (int i = front; i <= rear; i++) {
cout << Q[i] << " ";
}cout << endl;
}

You might also like