Open Lyo001 opened 1 month ago
int queue[CAPACITY]; unsigned int size = 0; int front = 0; unsigned int rear = CAPACITY - 1;
int enqueue(int data); int dequeue(); int isEmpty(); int display();
int main() { int ch, data; while (1) { printf("QUEUE ARRAY IMPLEMENTATION\n"); printf("1. Enqueue\n"); printf("2. Dequeue\n"); printf("3. Display\n"); printf("0. Exit\n"); printf("Enter your choice: "); scanf("%d", &ch);
switch (ch) {
case 1:
printf("\nEnter data to enqueue: ");
scanf("%d", &data);
enqueue(data);
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 0:
exit(0);
default:
printf("\nInvalid choice! Please try again.\n");
}
}
return 0;
}
struct Queue { int item[MAX]; int front; int rear; };
int main() { struct Queue q; q.front = -1; q.rear = -1;
if (q.rear == MAX - 1) {
printf("Queue is full\n");
} else {
int value = 10;
if (q.front == -1) q.front = 0;
q.rear++;
q.item[q.rear] = value;
printf("Enqueued: %d\n", value);
}
if (q.front == -1 || q.front > q.rear) {
printf("Queue is empty\n");
} else {
int dequeuedValue = q.item[q.front];
q.front++;
printf("Dequeued: %d\n", dequeuedValue);
if (q.front > q.rear) {
q.front = q.rear = -1;
}
}
return 0;
}
void enqueue(); void dequeue(); void show(); void frontandrear();
int inp_arr[SIZE]; int Rear = -1; int Front = -1;
void main() { int ch; while (1) { printf("1. Enqueue Operation\n"); printf("2. Dequeue Operation\n"); printf("3. Display the Queue\n"); printf("4. Exit\n"); printf("5. Display front and rear\n"); printf("Enter your choice of operations: "); scanf("%d", &ch);
switch (ch) {
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
show();
break;
case 4:
exit(0);
case 5:
frontandrear();
break;
default:
printf("Incorrect choice\n");
}
}
}
void enqueue() { int insert_item; if (Rear == SIZE - 1) { printf("Overflow\n"); } else { if (Front == -1) Front = 0; printf("Element to be inserted in the Queue: "); scanf("%d", &insert_item); Rear = Rear + 1; inp_arr[Rear] = insert_item; } }
void dequeue() { if (Front == -1 || Front > Rear) { printf("Underflow\n"); return; } else { printf("Element deleted from the Queue: %d\n", inp_arr[Front]); Front = Front + 1; } }
void show() { if (Front == -1) { printf("Empty Queue\n"); } else { printf("Queue: \n"); for (int i = Front; i <= Rear; i++) printf("%d ", inp_arr[i]); printf("\n"); } }
void frontandrear() { printf("Front is %d and rear is %d\n", inp_arr[Front], inp_arr[Rear]); }
include
define MAX_SIZE 100
struct Queue { int queue[MAX_SIZE]; int front; int rear; };
void initializeQueue(struct Queue *q) { q->front = -1; q->rear = -1; }
int isEmpty(struct Queue *q) { return (q->front == -1); }
int isFull(struct Queue *q) { return (q->rear == MAX_SIZE - 1); }
void enqueue(struct Queue *q, int data) { if (isFull(q)) { printf("Queue is full\n"); return; }
}
int dequeue(struct Queue *q) { if (isEmpty(q)) { printf("Queue is empty\n"); return -1; }
}
void peek(struct Queue *q) { if (isEmpty(q)) { printf("Queue is empty\n"); return; }
}
int main() { int a, b, c; struct Queue q;
}