cqueuecircular-queue

Why is the variable value changing automatically?


This is my code

    int front=-1, rear=-1, CQUEUE[MAX];
    int isFull()
    {
      if((rear=MAX-1 && front==0) || front==rear+1)
        return 1;
      else
        return 0;
    }
    void enQueue()
    {
      printf("\nValue of rear=%d front=%d",rear,front);
      char ch;
      if(!isFull())
      {
        printf("\nValue of rear=%d front=%d",rear,front);
      ......

This is the output on calling the function enQueue()

Value of rear=-1 front=-1
Value of rear=0 front=-1

The value of rear is getting increased by 1 although I'm not increasing it manually.


Solution

  • Look at your first if statement.

    if (rear=MAX-1  ...)
    // maybe better if you type:
    if (rear==MAX-1 ...)