Pointers to structures

Posted by blacktooth on Stack Overflow See other posts from Stack Overflow or by blacktooth
Published on 2010-05-22T20:39:26Z Indexed on 2010/05/22 20:40 UTC
Read the original article Hit count: 508

Filed under:
|
|
|
typedef struct queue {

  int q[max];
  int qhead;
  int qrear;

} queue;


void init_queue(queue *QUEUE)
{
  QUEUE.qhead = 0;
  QUEUE.qrear = -1;
}
void enqueue(queue *QUEUE,int data)
{
  QUEUE.qrear++;
  QUEUE.q[QUEUE.qrear] = data;
}

int process_queue(queue *QUEUE)
{
  if(QUEUE.qhead > QUEUE.qrear) 
    return -1;
  else
    return QUEUE.q[QUEUE.qhead++];
}

I am implementing queues using arrays just to keep it simple. Wats the error with the above code?

© Stack Overflow or respective owner

Related posts about c

    Related posts about struct