#define TRUE 1
#define FALSE 0
struct queue_element{
int data;
struct queue_element *next;
};
typedef struct queue_element queue_info;
typedef struct qpointer{
queue_info *front, *rear;
}queue;
queue *q;
queue *create()
{
queue *p;
p=(queue *)malloc(sizeof(queue));
p->front=NULL;
p->rear=NULL;
return(p);
}
int isempty(queue *q)
{
if(q->front == NULL)
return(TRUE);
else
return(FALSE);
}
void insert_queue (queue *q,int item)
{
queue_info *new;
new=(queue_info *) malloc (sizeof (queue_info));
new->next = NULL;
new->data = item;
if (isempty(q))
{
q->front = new;
q->rear = new;
}
else
{
q->rear->next=new;
q->rear=new;
}
return;
}
int delete_queue(queue *q)
{
int item;
queue_info *del;
if (isempty(q))
{
printf(“Queue is empty ! \n”);
return(-1);
}
else
{
del=q->front;
q->front=q->front->next;
item=del->data;
free (del);
if(q->front == NULL)
q->rear=NULL;
return(item);
}
}
No comments:
Post a Comment