Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions data_structures/queue_using_array2.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
#include <iostream>
using namespace std;

int queue[10];
int front = 0;
int rear = 0;

void Enque(int x) {
if (rear == 10) {
cout << "\nOverflow";
std::cout << "\nOverflow";
} else {
queue[rear++] = x;
}
}

void Deque() {
if (front == rear) {
cout << "\nUnderflow";
std::cout << "\nUnderflow";
}

else {
cout << "\n" << queue[front++] << " deleted";
std::cout << "\n" << queue[front++] << " deleted";
for (int i = front; i < rear; i++) {
queue[i - front] = queue[i];
}
Expand All @@ -30,21 +29,21 @@ void Deque() {

void show() {
for (int i = front; i < rear; i++) {
cout << queue[i] << "\t";
std::cout << queue[i] << "\t";
}
}

int main() {
int ch, x;
do {
cout << "\n1. Enque";
cout << "\n2. Deque";
cout << "\n3. Print";
cout << "\nEnter Your Choice : ";
cin >> ch;
std::cout << "\n1. Enque";
std::cout << "\n2. Deque";
std::cout << "\n3. Print";
std::cout << "\nEnter Your Choice : ";
std::cin >> ch;
if (ch == 1) {
cout << "\nInsert : ";
cin >> x;
std::cout << "\nInsert : ";
std::cin >> x;
Enque(x);
} else if (ch == 2) {
Deque();
Expand All @@ -54,4 +53,4 @@ int main() {
} while (ch != 0);

return 0;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

Loading