Homework Solution: The header file, queue.h, should look like:…

    The QUEUE class The header file, queue.h, should look like:
        #ifndef __QUEUE_INCLUDED__
        #define __QUEUE_INCLUDED__
    
        #include <stdio.h>
    
        typedef struct queue QUEUE;
    
        extern QUEUE *newQUEUE(void (*d)(FILE *,void *)); 
        extern void enqueue(QUEUE *items,void *value);
        extern void *dequeue(QUEUE *items);
        extern void *peekQUEUE(QUEUE *items);
        extern int sizeQUEUE(QUEUE *items);
        extern void displayQUEUE(FILE *,QUEUE *items);
        extern void visualizeQUEUE(FILE *,QUEUE *items);
    
        #endif
    
    The header file contains the function signatures of your public methods while the code module, queue.c, contains their implementations. The only local includes that queue.c should have are queue.h and the header file of the underlying data structure on which the array is based. Method behavior Here are some of the behaviors your methods should have. This listing is not exhaustive; you are expected, as a computer scientist, to complete the implementation in the best possible and most logical manner. newQUEUE - The constructor is passed a function that knows how to display the generic values stored in the queue. That function is stored in a display field of the QUEUE object: enqueue - The enqueue method runs in constant or amortized constant time. The value to be enqueued is stored in the underlying data structure. removeQUEUE - The dequeue method runs in constant or amortized constant time. The value to be dequeued is removed in the underlying data structure. peekQUEUE - The peek method returns the value ready to come off the queue, but leaves the queue unchanged. It runs in constant time. sizeQUEUE - The size method returns the number of items stored in the queue. It runs in amortized constant time. displayQUEUE - This display method prints the items stored in the queue. If the integers 5, 6, 2, 9, and 1 are enqueued in the order given, the method would generate this output:
        <5,6,2,9,1>
    
    with no preceding or following whitespace. An empty queue displays as <>. visualizeQUEUE - The visualize method simply calls the display method of the data structure upon which the queue is based. Assertions Include the following assertions in your methods: newQUEUE - The memory allocated shall not be zero. dequeue - The size shall be greater than zero. peekQUEUE - The size shall be greater than zero.

    Expert Answer

     
    #include <stdio.h> #define MAX 50

    The QUEUE class

    The header rasp, queue.h, should face like:

        #ifndef __QUEUE_INCLUDED__
        #define __QUEUE_INCLUDED__
    
        #include <stdio.h>
    
        typedef struct queue QUEUE;
    
        extern QUEUE *newQUEUE(vacant (*d)(FILE *,vacant *)); 
        extern vacant enqueue(QUEUE *items,vacant *value);
        extern vacant *dequeue(QUEUE *items);
        extern vacant *peekQUEUE(QUEUE *items);
        extern int magnitudeQUEUE(QUEUE *items);
        extern vacant exhibitQUEUE(FILE *,QUEUE *items);
        extern vacant visualizeQUEUE(FILE *,QUEUE *items);
    
        #endif
    

    The header rasp contains the administration signatures of your social ways occasion the edict module, queue.c, contains their implementations.

    The singly persomal includes that queue.c should keep are queue.h and the header rasp of the underlying facts construction on which the marshal is naturalized.

    Way behavior

    Here are some of the behaviors your ways should keep. This listing is referable attributable attributable attributable exhaustive; you are expected, as a computer gownsman, to finished the implementation in the best likely and most close style.

    newQUEUE – The producer is passed a administration that knows how to exhibit the collective rates stored in the queue. That administration is stored in a display field of the QUEUE object:

    enqueue – The enqueue way runs in perpetual or amortized perpetual term. The rate to be enqueued is stored in the underlying facts construction.

    removeQUEUE – The dequeue way runs in perpetual or amortized perpetual term. The rate to be dequeued is removed in the underlying facts construction.

    peekQUEUE – The peek way inend the rate apt to end unstudied the queue, referablewithstanding leaves the queue unchanged. It runs in perpetual term.

    sizeQUEUE – The magnitude way inend the number of items stored in the queue. It runs in amortized perpetual term.

    displayQUEUE – This exhibit way prints the items stored in the queue. If the integers 5, 6, 2, 9, and 1 are enqueued in the adjust given, the way would propagate this output:

        <5,6,2,9,1>
    

    with no precedent or forthcoming whitespace. An leisure queue exhibits as <>.

    visualizeQUEUE – The visualize way merely calls the exhibit way of the facts construction upon which the queue is naturalized.

    Assertions

    Include the forthcoming assertions in your ways:

    newQUEUE – The retrospect integralocated shintegral referable attributable attributable attributable be nothing.

    dequeue – The magnitude shintegral be senior than nothing.

    peekQUEUE – The magnitude shintegral be senior than nothing.

    Expert Retort

     

    #include <stdio.h>

    #define MAX 50
    int queue_array[MAX];
    int derangement = – 1;
    int face = – 1;
    main()
    {
    int precious;
    occasion (1)
    {
    printf(“1.Introduce part to queue n”);
    printf(“2.Delete part from queue n”);
    printf(“3.Exhibit integral parts of queue n”);
    printf(“4.Quit n”);
    printf(“Enter your precious : “);
    scanf(“%d”, &choice);
    switch (choice)
    {
    case 1:
    insert();
    break;
    case 2:
    delete();
    break;
    case 3:
    display();
    break;
    case 4:
    exit(1);
    default:
    printf(“Wrong precious n”);
    } /*End of switch*/
    } /*End of occasion*/
    } /*End of main()*/
    insert()
    {
    int add_item;
    if (derangement == MAX – 1)
    printf(“Queue Overflow n”);
    else
    {
    if (face == – 1)
    /*If queue is initially leisure */
    face = 0;
    printf(“Inset the part in queue : “);
    scanf(“%d”, &add_item);
    derangement = derangement + 1;
    queue_array[rear] = add_item;
    }
    } /*End of introduce()*/

    delete()
    {
    if (face == – 1 || face > derangement)
    {
    printf(“Queue Underflow n”);
    return ;
    }
    else
    {
    printf(“Part deleted from queue is : %dn”, queue_array[front]);
    face = face + 1;
    }
    } /*End of delete() */
    display()
    {
    int i;
    if (face == – 1)
    printf(“Queue is leisure n”);
    else
    {
    printf(“Queue is : n”);
    for (i = face; i <= derangement; i++)
    printf(“%d “, queue_array[i]);
    printf(“n”);
    }
    } /*End of exhibit() *