H
herrcho
#include <stdio.h>
#define MAX 10
int queue[MAX];
int front, rear;
void init_queue()
{
front=rear=0;
}
void clear_queue(void)
{
front=rear;
}
int put(int k)
{
if ( (rear + 1) % MAX == front)
{
printf("\n Queue overflow.");
return -1;
}
queue[rear] = k;
rear = ++rear % MAX; <------------------------ 1
return k;
}
int get()
{
int i;
if (front == rear)
{
printf("\n Queue underflow.");
return -1;
}
i = queue[front];
front = ++front % MAX; <------------------------------- 2
return i;
}
void print_queue(void)
{
int i;
printf("\n Queue contents : Front -------> Rear \n");
for (i=front;i != rear ;i = ++i % MAX )
printf("%-6d", queue);
the above is for implementing 'Circular Queue' data structure using
array.
when i complile it. 1 & 2 line shows the following warning message .
operation on `rear' may be undefined.
operation on `front' may be undefined.
but executues alright.. Did i miss something ?
#define MAX 10
int queue[MAX];
int front, rear;
void init_queue()
{
front=rear=0;
}
void clear_queue(void)
{
front=rear;
}
int put(int k)
{
if ( (rear + 1) % MAX == front)
{
printf("\n Queue overflow.");
return -1;
}
queue[rear] = k;
rear = ++rear % MAX; <------------------------ 1
return k;
}
int get()
{
int i;
if (front == rear)
{
printf("\n Queue underflow.");
return -1;
}
i = queue[front];
front = ++front % MAX; <------------------------------- 2
return i;
}
void print_queue(void)
{
int i;
printf("\n Queue contents : Front -------> Rear \n");
for (i=front;i != rear ;i = ++i % MAX )
printf("%-6d", queue);
the above is for implementing 'Circular Queue' data structure using
array.
when i complile it. 1 & 2 line shows the following warning message .
operation on `rear' may be undefined.
operation on `front' may be undefined.
but executues alright.. Did i miss something ?