Posts

Code

 #include <stdio.h> #include <stdlib.h> // Function to merge two subarrays of arr[] void merge(int arr[], int left, int middle, int right) {     int i, j, k;     int n1 = middle - left + 1;     int n2 = right - middle;     // Create temporary arrays     int L[n1], R[n2];     // Copy data to temporary arrays L[] and R[]     for (i = 0; i < n1; i++)         L[i] = arr[left + i];     for (j = 0; j < n2; j++)         R[j] = arr[middle + 1 + j];     // Merge the temporary arrays back into arr[l..r]     i = 0; // Initial index of first subarray     j = 0; // Initial index of second subarray     k = left; // Initial index of merged subarray     while (i < n1 && j < n2) {         if (L[i] <= R[j]) {             arr[k] = L[i];             i++;         } else {             arr[k] = R[j];             j++;         }         k++;     }     // Copy the remaining elements of L[], if there are any     while (i < n1) {         arr[k] = L[i];         i++;        
Write a program to implement Circular Queue using Array in c language  ChatGPT Certainly! Here's a simple implementation of a Circular Queue using an array in the C language: c Copy code #include <stdio.h> #define MAX_SIZE 5 // Structure to represent the Circular Queue struct CircularQueue {     int items[MAX_SIZE];     int front, rear; }; // Function to initialize the Circular Queue void initializeQueue(struct CircularQueue* queue) {     queue->front = -1;     queue->rear = -1; } // Function to check if the Circular Queue is empty int isEmpty(struct CircularQueue* queue) {     return (queue->front == -1 && queue->rear == -1); } // Function to check if the Circular Queue is full int isFull(struct CircularQueue* queue) {     return ((queue->rear + 1) % MAX_SIZE == queue->front); } // Function to enqueue an element into the Circular Queue void enqueue(struct CircularQueue* queue, int value) {     if (isFull(queue)) {         printf("Queue is full.