icon

UseTopicwritingscode to get 5% OFF on your first order!

Assignment With Help Of C Programming

#include <stdio.h>

#include <stdlib.h>

#include <stdbool.h>

#define MAX 6 

int itemCount = 0;

void Print(int intArray[]);

int peek(int intArray[]) {

    return intArray[0];

}

bool isEmpty(int intArray[]){

    return itemCount == 0;

}

bool isFull(int intArray[]){

    return itemCount == MAX;

}

int size(){

    return itemCount;

}

void enQueue(int data, int intArray[]){

    if(!isFull(intArray)) {

        intArray[size()] = data;

        itemCount++;

    }

    else

    {

        printf(“Error: The queue is full.n”);

    }

}

int deQueue(int intArray[]){

    int data = -1;

    if(isEmpty(intArray)) {

        printf(“Error: The queue is empty.n”);

    }

    else

    {

        data = intArray[0];

        for(int i = 0; i < MAX-1; i++)

        {

            intArray[i] = intArray[i+1];

        }

        itemCount–;

    }

    

    return data;

    

}

int main() {

    

    int intArray[MAX] = {0,0,0,0,0,0};

    //USE max

    for(int i = 0; i < MAX+1; i++)

    {

        printf(“EnQueue %dn”, i*3);

        enQueue(i*3, intArray);

        Print(intArray);

    }

    for(int i = 0; i < MAX+1; i++)

    {

        int data = deQueue(intArray);

        printf(“DeQueue %dn”, data);

        Print(intArray);

    }

    return (EXIT_SUCCESS);

}

void Print(int intArray[])

{

    printf(“size : %dn”, size());

    printf(“——————————–n”);

    printf(“index : “);

    for(int iter=0; iter<size(); iter++)

    {

        printf(“dt”, iter);

        

    }

    printf(“n—————————n”);

    printf(“queue : “);

    for(int iter= 0; iter < size(); iter++)

    {

        printf(“%dt”, intArray[iter]);

        

    }

    printf(“n————————n”);

}

You can leave a response, or trackback from your own site.

Leave a Reply

Powered by WordPress | Designed by: Premium WordPress Themes | Thanks to Themes Gallery, Bromoney and Wordpress Themes