Respuesta :

The functions int queue[MAXSIZE]; int deque[MAX]; arrayname.front() can be used to implement enqueue, dequeue and front functions of generic array.

What are the codes for enqueue(), dequeue(), and front() functions in C?

#include <stdio.h>

#define MAXSIZE 10

int queue[MAXSIZE];

int front = -1;

int rear = -1;

int size = -1;

int isempty()

{

   return size<0;

}

int isfull()

{

   return size == MAXSIZE;

}

void enqueue(int value)

{

   if(size<MAXSIZE)

   {

       if(size<0)

       {

           queue[0] = value;

           front = rear = 0;

           size = 1;

       }

       else if(rear == MAXSIZE-1)

       {

           queue[0] = value;

           rear = 0;

           size++;

       }

       else

       {

           queue[rear+1] = value;

           rear++;

           size++;

       }

   }

   else

   {

       printf("Queue is full\n");

   }

}

int dequeue()

{

   if(size<0)

   {

       printf("Queue is empty\n");

   }

   else

   {

       size--;

       front++;

   }

}

int Front()

{

   return queue[front];

}

void display()

{

   int i;

   if(rear>=front)

   {

       for(i=front;i<=rear;i++)

       {

           printf("%d\n",queue[i]);

       }

   }

   else

   {

       for(i=front;i<MAXSIZE;i++)

       {

           printf("%d\n",queue[i]);

       }

       for(i=0;i<=rear;i++)

       {

           printf("%d\n",queue[i]);

       }

   }

}

int main()

{

   enqueue(4);

   enqueue(8);

   enqueue(10);

   enqueue(20);

   display();

   dequeue();

   printf("After dequeue\n");

   display();

   enqueue(50);

   enqueue(60);

   enqueue(70);

   enqueue(80);

   dequeue();

   enqueue(90);

   enqueue(100);

   printf("After enqueue\n");

   display();

   return 0;

}

// CPP program to illustrate

// application Of front() and back() function

#include <array>

#include <iostream>

using namespace std;

int main()

{

array<int, 8> myarray{ 1, 2, 3, 4, 5, 6, 7, 8 };

// Array becomes 1, 2, 3, 4, 5, 6, 7, 8

if (myarray.front() > myarray.back()) {

 cout << myarray.front() - myarray.back();

}

else if (myarray.front() < myarray.back()) {

 cout << myarray.back() - myarray.front();

}

else

 cout << "0";

}

To know more about enqueue, dequeue and front functions in C refer:

https://brainly.com/question/18801196

#SPJ4