Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
C++
  1  #include <stdio.h>
  2  #include <stdlib.h>
  3  
  4  #define QUEUE_SIZE 5
  5  
  6  struct queue
  7  {
  8      int items[QUEUE_SIZE];
  9      int front;
 10      int rear;
 11  };
 12  
 13  typedef struct queue QUEUE;
 14  
 15  int insert_rear(int item, QUEUE *q)
 16  {
 17      if (q->rear == QUEUE_SIZE - 1)
 18      {
 19          printf("\nQueue is full , insertion at rear end is not possible ");
 20          return 0;
 21      }
 22      (q->rear)++;
 23      q->items[q->rear] = item;
 24  };
 25  
 26  int delete_front(QUEUE *q)
 27  {
 28      if (q->front > q->rear)
 29      {
 30          printf("\nQueue is empty,deletion is not possible");
 31          return 0;
 32      }
 33      printf("the element deleted is %d\n", q->items[q->front]);
 34      (q->front)++;
 35  
 36      if (q->front > q->rear)
 37      {
 38          q->front = 0;
 39          q->rear = -1;
 40      }
 41  }
 42  
 43  int display(QUEUE *q)
 44  {
 45      int i;
 46      if (q->front > q->rear)
 47      {
 48          printf("\nQueue is empty,can't display the contents");
 49          return 0;
 50      }
 51      printf("\nThe Queue contents are:\n");
 52  
 53      for (i = q->front; i <= q->rear; i++)
 54      {
 55          printf("%d\t", q->items[i]);
 56      }
 57      int main()
 58      {
 59          QUEUE q;
 60          q.front = 0;
 61          q.rear = -1;
 62          int input, item;
 63          for (;;)
 64          {
 65              printf("\n1 to insert rear");
 66              printf("\n2 to delte front");
 67              printf("\n3 to display content of the queue");
 68              printf("\n4 to exit");
 69              printf("\n1 enter the choice:");
 70              scanf("%d", &input);
 71              switch (input)
 72              {
 73              case 1:
 74                  printf("\nEnter the item to be inserted:");
 75                  scanf("%d", &item);
 76                  insert_rear(item, &q);
 77                  display(&q);
 78                  break;
 79  
 80              case 2:
 81                  delete_front(&q);
 82                  display(&q);
 83                  break;
 84  
 85              case 3:
 86                  display(&q);
 87                  break;
 88  
 89              case 4:
 90                  exit(0);
 91                  break;
 92  
 93              default:
 94                  printf("\n invaid choice");
 95                  continue;
 96              }
 97          }
 98      }


What I have tried:

int main();
    {
        QUEUE q;
        q.front = 0;
        q.rear = -1;
        int input, item;
        for (;;)
        {
            printf("\n1 to insert rear");
            printf("\n2 to delte front");
            printf("\n3 to display content of the queue");
            printf("\n4 to exit");
            printf("\n1 enter the choice:");
            scanf("%d", &input);
            switch (input)
            {
            case 1:
                printf("\nEnter the item to be inserted:");
                scanf("%d", &item);
                insert_rear(item, &q);
                display(&q);
                break;

            case 2:
                delete_front(&q);
                display(&q);
                break;

            case 3:
                display(&q);
                break;

            case 4:
                exit(0);
                break;

            default:
                printf("\n invaid choice");
                continue;
            }
        }
    }
Posted
Updated 6-May-22 22:55pm
v2
Comments
Patrice T 7-May-22 3:55am    
And you think you can tell us which errors you want to fix ?
Member 15627552 7-May-22 4:05am    
after compiling the code the error are showing:
/tmp/RKFbMan9Eg.c: In function 'display':
/tmp/RKFbMan9Eg.c:98:5: error: expected declaration or statement at end of input
98 | }
| ^

can u fix all the error
Patrice T 7-May-22 4:14am    
Use Improve question to update your question.
So that everyone can pay attention to this information.

Line 24 has an unneeded semi-colon after the close brace. And there should be another close brace on a line after line 98.
 
Share this answer
 
To add to what Richard has rightly said, syntax errors like these are a fact of life, and we all meet them on a daily basis - often several per minute if you aren't careful.
So it's worth investing a couple of minutes in learning how to spot and fix them yourself as it's really easy, and a lot quicker than waiting the best part of an hour for someone else to fix them for you each time!

This may help you next time you get a compilation error: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900