Upload files to "DS/C/endsem-omnibus"
This commit is contained in:
parent
c53746d826
commit
091ec8cd90
4 changed files with 653 additions and 0 deletions
79
DS/C/endsem-omnibus/queues.c
Normal file
79
DS/C/endsem-omnibus/queues.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define MAX 5
|
||||
|
||||
int queue[MAX];
|
||||
int front = -1, rear = -1;
|
||||
|
||||
void enqueue() {
|
||||
int item;
|
||||
if(rear == MAX-1) {
|
||||
printf("\nQueue is Full");
|
||||
}
|
||||
else {
|
||||
printf("\nEnter element to insert: ");
|
||||
scanf("%d", &item);
|
||||
if(front == -1 && rear == -1) {
|
||||
front = rear = 0;
|
||||
}
|
||||
else {
|
||||
rear++;
|
||||
}
|
||||
queue[rear] = item;
|
||||
printf("\nItem inserted successfully");
|
||||
}
|
||||
}
|
||||
|
||||
void dequeue() {
|
||||
if(front == -1 || front > rear) {
|
||||
printf("\nQueue is Empty");
|
||||
}
|
||||
else {
|
||||
printf("\nDeleted element is: %d", queue[front]);
|
||||
if(front == rear) {
|
||||
front = rear = -1;
|
||||
}
|
||||
else {
|
||||
front++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void display() {
|
||||
int i;
|
||||
if(front == -1 || front > rear) {
|
||||
printf("\nQueue is Empty");
|
||||
}
|
||||
else {
|
||||
printf("\nQueue elements are:\n");
|
||||
for(i = front; i <= rear; i++) {
|
||||
printf("%d ", queue[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int choice;
|
||||
while(1) {
|
||||
printf("\n\n1. Insert\n2. Delete\n3. Display\n4. Exit");
|
||||
printf("\nEnter your choice: ");
|
||||
scanf("%d", &choice);
|
||||
|
||||
switch(choice) {
|
||||
case 1:
|
||||
enqueue();
|
||||
break;
|
||||
case 2:
|
||||
dequeue();
|
||||
break;
|
||||
case 3:
|
||||
display();
|
||||
break;
|
||||
case 4:
|
||||
exit(0);
|
||||
default:
|
||||
printf("\nInvalid Choice");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue