Array Implementation of a Stack in C Programming


#include <stdio.h>
#include <stdlib.h>
#define MAX 10

void insert(int queue[], int *rear, int value)
{
   if(*rear < MAX-1)
   {
      *rear= *rear +1;
      queue[*rear] = value;
   }
   else
   {
      printf("The queue is full can not insert a value\n");
      exit(0);
   }
}

void delete(int queue[], int *front, int rear, int * value)
{
   if(*front == rear)
   {
      printf("The queue is empty can not delete a value\n");
      exit(0);
   }
   *front = *front + 1;
   *value = queue[*front];
}

main()
{
   int queue[MAX];
   int front,rear;
   int n,value;
   front = rear = -1;

   insert(queue,&rear,1);
   insert(queue,&rear,2);

   delete(queue,&front,rear,&value);
   printf("The value deleted is %d\n",value);
   
   getch();
}

Comments

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples