Code Monkey home page Code Monkey logo

gender-classificatiuon's Introduction

Ex.No.03

circular queue.

Aim:

To write a C program to insert and delete elements in circular queue.

Algorithm:

Code:

#include<stdio.h>

#include<stdlib.h>

#define max 10
int insq(int cqueue[max], int *front, int *rear, int *data)
{
      if((*rear + 1) % max == *front)
            return(-1);
      else
      {
            *rear = (*rear + 1) % max;
            cqueue[*rear] = *data;
            return(1);
      }
}
int delq(int cqueue[max], int *front, int *rear, int *data)
{
      if(*front == *rear)
            return(-1);
      else
      {
            *front = (*front + 1) % max;
            *data = cqueue[*front];
            return(1);
      }
}
int main()
{
      int cqueue[max], data;
      int front, rear, reply,ch;
      front = rear = 0; //... Initialize Circular Queue
      printf("-------------------------------------\n");
      printf("\tMenu");
      printf("\n------------------------------------");
      printf("\n 1. Insert number in a Circular Queue");
      printf("\n 2 .Delete number from Circular Queue");
      printf("\n 3. Exit \n");
      printf("------------------------------------\n");
      while(1)
      {
            printf("Choose operation : ");
            scanf("%d", &ch);
            switch(ch)
            {
                  case 1 : // insert
                        printf("\nEnter number: ");
                        scanf("%d", &data);
                        reply = insq(cqueue, &front, &rear, &data);
                        if(reply == -1)
                              printf("\nCircular Queue is Full \n");
                        else
                              printf("%d is inserted in a Circular Queue\n\n", data);
                        break;
                  case 2 : // delete
                        reply = delq(cqueue, &front, &rear,&data);
                        if(reply == -1)
                              printf("\n Circular Queue is Empty \n");
                        else
                              printf("\n %d is deleted from Circular Queue \n", data);
                        printf("\n");
                        break;
                  case 3 : exit(0);
                  default: printf("Invalid operation \n");
            }
      }
      return 0;
}

Output:

dsss

Result:

Thus, a C program to insert and delete elements into the circular queue is developed and executed successfully.

gender-classificatiuon's People

Contributors

durga46 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.