#include <stdio.h>

int main() {
    int arr[50], f = -1, r = -1, n, a, b;

    do {
        printf("Press 1 for Enqueue\n2 for Peek\n3 for Dequeue\n4 for exit\n");
        scanf("%d", &a);

        switch (a) {
            case 1:
                printf("Give the size of the array (limit is 50):\n");
                scanf("%d", &n);

                for (int i = 0; i < n; i++) {
                    if (i == 0) {
                        r = r + 1;
                        f = f + 1;

                        printf("Enqueueing the %dth value of array:\n", i);
                        scanf("%d", &arr[i]);

                        printf("Do you want to continue?\nPress 1 for yes\n2 for No\n");
                        scanf("%d", &b);

                        if (b == 2) {
                            printf("Ending Enqueue function...\n");
                            break;
                        }

                    } else {
                        printf("Enqueueing the %dth value of array:\n", i);
                        scanf("%d", &arr[i]);

                        printf("Do you want to continue?\nPress 1 for yes\n2 for No\n");
                        scanf("%d", &b);

                        if (b == 2) {
                            printf("Ending Enqueue function...\n");
                            break;
                        }
                        r = r + 1;
                    }
                }
                printf("Overflow!\n");
                break;

            case 2:
                if (f == -1) {
                    printf("Queue is empty!\n");
                } else {
                    printf("Peeking value at index %d of the array: %d\n", r, arr[r]);
                }
                break;

            case 3:
                if (f == -1) {
                    printf("Queue is empty!\n");
                } else {
                    for (int i = f; i <= r; i++) {
                        printf("Dequeuing the %dth value: %d\n", i, arr[i]);

                        printf("Do you want to continue?\nPress 1 for yes\n2 for No\n");
                        scanf("%d", &b);

                        if (b == 2) {
                            printf("Ending Dequeue function...\n");
                            break;
                        }
                    }
                }
                break;

            case 4:
                printf("Exiting...\n");
                break;

            default:
                printf("Wrong input!\n");
                break;
        }

    } while (a != 4);

    return 0;
}					class Queue { 
    private static int front, rear, capacity; 
    private static int queue[]; 
   
    Queue(int size) { 
        front = rear = 0; 
        capacity = size; 
        queue = new int[capacity]; 
    } 
   
    // insert an element into the queue
    static void queueEnqueue(int item)  { 
        // check if the queue is full
        if (capacity == rear) { 
            System.out.printf("\nQueue is full\n"); 
            return; 
        } 
   
        // insert element at the rear 
        else { 
            queue[rear] = item; 
            rear++; 
        } 
        return; 
    } 
   
    //remove an element from the queue
    static void queueDequeue()  { 
        // check if queue is empty 
        if (front == rear) { 
            System.out.printf("\nQueue is empty\n"); 
            return; 
        } 
   
        // shift elements to the right by one place uptil rear 
        else { 
            for (int i = 0; i < rear - 1; i++) { 
                queue[i] = queue[i + 1]; 
            } 
   
       
      // set queue[rear] to 0
            if (rear < capacity) 
                queue[rear] = 0; 
   
            // decrement rear 
            rear--; 
        } 
        return; 
    } 
   
    // print queue elements 
    static void queueDisplay() 
    { 
        int i; 
        if (front == rear) { 
            System.out.printf("Queue is Empty\n"); 
            return; 
        } 
   
        // traverse front to rear and print elements 
        for (i = front; i < rear; i++) { 
            System.out.printf(" %d = ", queue[i]); 
        } 
        return; 
    } 
   
    // print front of queue 
    static void queueFront() 
    { 
        if (front == rear) { 
            System.out.printf("Queue is Empty\n"); 
            return; 
        } 
        System.out.printf("\nFront Element of the queue: %d", queue[front]); 
        return; 
    } 
} 
 
public class Main {
    public static void main(String[] args) { 
        // Create a queue of capacity 4 
        Queue q = new Queue(4); 
   
        System.out.println("Initial Queue:");
       // print Queue elements 
        q.queueDisplay(); 
   
        // inserting elements in the queue 
        q.queueEnqueue(10); 
        q.queueEnqueue(30); 
        q.queueEnqueue(50); 
        q.queueEnqueue(70); 
   
        // print Queue elements 
        System.out.println("Queue after Enqueue Operation:");
        q.queueDisplay(); 
   
        // print front of the queue 
        q.queueFront(); 
         
        // insert element in the queue 
        q.queueEnqueue(90); 
   
        // print Queue elements 
        q.queueDisplay(); 
   
        q.queueDequeue(); 
        q.queueDequeue(); 
        System.out.printf("\nQueue after two dequeue operations:"); 
   
        // print Queue elements 
        q.queueDisplay(); 
   
        // print front of the queue 
        q.queueFront(); 
    } 
}// Java program to implement a queue using an array
class Queue {
    private int front, rear, capacity;
    private int queue[];
 
    Queue(int c)
    {
        front = rear = 0;
        capacity = c;
        queue = new int[capacity];
    }
 
    // function to insert an element
    // at the rear of the queue
    static void queueEnqueue(int data)
    {
        // check queue is full or not
        if (capacity == rear) {
            System.out.printf("\nQueue is full\n");
            return;
        }
 
        // insert element at the rear
        else {
            queue[rear] = data;
            rear++;
        }
        return;
    }
 
    // function to delete an element
    // from the front of the queue
    static void queueDequeue()
    {
        // if queue is empty
        if (front == rear) {
            System.out.printf("\nQueue is empty\n");
            return;
        }
 
        // shift all the elements from index 2 till rear
        // to the right by one
        else {
            for (int i = 0; i < rear - 1; i++) {
                queue[i] = queue[i + 1];
            }
 
            // store 0 at rear indicating there's no element
            if (rear < capacity)
                queue[rear] = 0;
 
            // decrement rear
            rear--;
        }
        return;
    }
 
    // print queue elements
    static void queueDisplay()
    {
        int i;
        if (front == rear) {
            System.out.printf("\nQueue is Empty\n");
            return;
        }
 
        // traverse front to rear and print elements
        for (i = front; i < rear; i++) {
            System.out.printf(" %d <-- ", queue[i]);
        }
        return;
    }
 
    // print front of queue
    static void queueFront()
    {
        if (front == rear) {
            System.out.printf("\nQueue is Empty\n");
            return;
        }
        System.out.printf("\nFront Element is: %d", queue[front]);
        return;
    }
}
 
public class StaticQueueinjava {
 
    // Driver code
    public static void main(String[] args)
    {
        // Create a queue of capacity 4
        Queue q = new Queue(4);
 
        // print Queue elements
        q.queueDisplay();
 
        // inserting elements in the queue
        q.queueEnqueue(20);
        q.queueEnqueue(30);
        q.queueEnqueue(40);
        q.queueEnqueue(50);
 
        // print Queue elements
        q.queueDisplay();
 
        // insert element in the queue
        q.queueEnqueue(60);
 
        // print Queue elements
        q.queueDisplay();
 
        q.queueDequeue();
        q.queueDequeue();
        System.out.printf("\n\nafter two node deletion\n\n");
 
        // print Queue elements
        q.queueDisplay();
 
        // print front of the queue
        q.queueFront();
    }
}

C相关代码片段

reddit photoshop will be deactivated popup macos

uppercase to lowercase in c

show available value

lowercase to uppercase in C

c switch return

how to change hte middle node in linked list C

openGL create shape

script to check program running and restart

printf("")

Rewind to a commit Git

mouse click for colab

how to remove newline in the end of fgets string

fit text to conatiner flutter

gorm string array

js observe url change

clock skew detected makefile

time() function in c

worst fit code in c

first fit code in c

roem evaluation pyspark

calculator c

safet algorith im c

c copy char*

jfug function

soil moisture sensor interfacing with ESP32

flutter sidebar menu example

access images in c panel htaccess file

c include header file in the folder aboce

c include libray

gcc name output file

C data link escape char

How to type DLE in C

vscode Ctrl+d undo

C[strtol] func

pointer c++

power in c

sort three numbers

strip in c

c time duration

overleaf itemize a b c

route groups

itoa c code

queue in c

'wsgirequest' object has no attribute 'get'

c copy file

how to print array data in html using javascript

hello world program in c

how to compare a variable with a string in c

c print array

c rand range

exponents without pow c

how to reversed number in c

c random number with range

pthread mutex destroy while lock

pthread init mutex twice

insert c or p

woocommerce align add to cart buttons

vscode fold all code when open file

commit github non funziona

makefile both c and c++

scanf with space

c macro variable arguments

c printf format

check if prime c

read file line by line c

c use define in string

pattern program in c

Write the code in C to implement selection sort

c program of Goldbach conjecture

otput only one decimal point in c

trim string c

tokenize string c

firebase message in app doesn't work

implementing stack using linked list

esercizi semplici con le funzioni in c

array to linked list in c

sorted array to bst implementation in c

doubly linked list insertion in the middle

arch distro

distance vector routing algorithm