Commit 5b28ee5a by malcolm

process queue structure

parent 9a970ebd
Showing with 72 additions and 0 deletions
#include "queue.h"
#define NULL 0
struct node
{
process* proc;
struct node *next;
};
struct node* node_create(process *proc)
{
struct node* n = malloc(sizeof(struct node));
n->next = NULL;
n->proc = proc;
return n;
}
void queue_push(queue q, process *proc)
{
struct node* n = node_create(proc);
if(q.rear!=NULL)
{
q.rear->next = n;
q.rear = n;
}
else
{
q.rear = q.front = n;
}
}
void queue_pop(queue q)
{
if(q.front!=NULL)
{
struct node* f =q.front->next;
//free(q.front)
q.front = f;
if(q.front==NULL)
{
q.rear=NULL;
}
}
}
process* queue_front(queue q)
{
return q.front->proc;
}
void create(queue q)
{
q.front = q.rear = NULL;
}
#ifndef _QUEUE_INC
#define _QUEUE_INC
#include "PCB.h"
struct node;
typedef struct
{
struct node *front,*rear;
} queue;
void queue_push(queue q, process *proc);
void queue_pop(queue q);
process* queue_front(queue q);
void create(queue q);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment