mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-02-09 13:37:25 +08:00
formatting source-code for d7af6fdc8c
This commit is contained in:
@@ -10,13 +10,15 @@
|
||||
|
||||
#define MAXSIZE 10
|
||||
|
||||
class Queue_Array {
|
||||
class Queue_Array
|
||||
{
|
||||
int front;
|
||||
int rear;
|
||||
int size;
|
||||
|
||||
public:
|
||||
Queue_Array() {
|
||||
Queue_Array()
|
||||
{
|
||||
front = -1;
|
||||
rear = -1;
|
||||
size = MAXSIZE;
|
||||
@@ -27,43 +29,59 @@ class Queue_Array {
|
||||
void display();
|
||||
};
|
||||
|
||||
void Queue_Array::enqueue(int ele) {
|
||||
if (rear == size - 1) {
|
||||
void Queue_Array::enqueue(int ele)
|
||||
{
|
||||
if (rear == size - 1)
|
||||
{
|
||||
std::cout << "\nStack is full";
|
||||
} else if (front == -1 && rear == -1) {
|
||||
}
|
||||
else if (front == -1 && rear == -1)
|
||||
{
|
||||
front = rear = 0;
|
||||
arr[rear] = ele;
|
||||
} else if (rear < size) {
|
||||
}
|
||||
else if (rear < size)
|
||||
{
|
||||
rear++;
|
||||
arr[rear] = ele;
|
||||
}
|
||||
}
|
||||
|
||||
int Queue_Array::dequeue() {
|
||||
int Queue_Array::dequeue()
|
||||
{
|
||||
int d;
|
||||
if (front == -1) {
|
||||
if (front == -1)
|
||||
{
|
||||
std::cout << "\nstack is empty ";
|
||||
return 0;
|
||||
} else if (front == rear) {
|
||||
}
|
||||
else if (front == rear)
|
||||
{
|
||||
d = arr[front];
|
||||
front = rear = -1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
d = arr[front++];
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
void Queue_Array::display() {
|
||||
if (front == -1) {
|
||||
void Queue_Array::display()
|
||||
{
|
||||
if (front == -1)
|
||||
{
|
||||
std::cout << "\nStack is empty";
|
||||
} else {
|
||||
for (int i = front; i <= rear; i++)
|
||||
std::cout << arr[i] << " ";
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = front; i <= rear; i++) std::cout << arr[i] << " ";
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
int op, data;
|
||||
|
||||
Queue_Array ob;
|
||||
@@ -72,21 +90,31 @@ int main() {
|
||||
std::cout << "\n2. dequeue(Deletion)";
|
||||
std::cout << "\n3. Display";
|
||||
std::cout << "\n4. Exit";
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
std::cout << "\nEnter your choice ";
|
||||
std::cin >> op;
|
||||
if (op == 1) {
|
||||
if (op == 1)
|
||||
{
|
||||
std::cout << "Enter data ";
|
||||
std::cin >> data;
|
||||
ob.enqueue(data);
|
||||
} else if (op == 2) {
|
||||
}
|
||||
else if (op == 2)
|
||||
{
|
||||
data = ob.dequeue();
|
||||
std::cout << "\ndequeue element is:\t" << data;
|
||||
} else if (op == 3) {
|
||||
}
|
||||
else if (op == 3)
|
||||
{
|
||||
ob.display();
|
||||
} else if (op == 4) {
|
||||
}
|
||||
else if (op == 4)
|
||||
{
|
||||
exit(0);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "\nWrong choice ";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user