'queue'에 해당되는 글 1건

/*↓↓↓↓↓↓↓↓↓선형  큐↓↓↓↓↓↓↓↓↓*/
#define MAX_QUEUE_SIZE 100
typedef struct{
 int key
}element;

element queue[MAX_QUEUE_SIZE];
int rear = -1;
int front = -1;

void addq(int *rear,element item)
{
 if(*rear == MAX_QUEUE_SIZE-1){
  queue_full();
  return;
 }
 queue[++*rear]=item;
}

void deleteq(int *front, int rear)
{
 if(*front == rear)
  return queue_empty;
 return queue[++*front];
}
/*↓↓↓↓↓↓↓↓↓원형  큐↓↓↓↓↓↓↓↓↓*/
int rear = 0;
int front = 0;

void addq(int front, int *rear,element item)
{
 *rear=(*rear+1) % MAX_QUEUE_SIZE;
 if(front == *rear){
  queue_full(rear);
  return ;
 }
 queue[*rear]=item;
}

void deleteq(int *front,int rear)
{
 element item;
 if(*front == rear)
  return queue_empty();
 *front=(*front+1) % MAX_QUEUE_SIZE;
 return queue[*front];
}
/*↓↓↓↓↓↓↓↓↓연결된 큐↓↓↓↓↓↓↓↓↓*/
#define MAX_QUEUES 10
typedef struct queue* queue_pointer;
typedef struct queue{
 element item;
 queue_pointer link;
};

queue_pointer front[MAX_QUEUE],rear[MAX_QUEUE];

void addq(queue_pointer* front,queue_pointer* rear,element item)
{
 queue_pointer temp = (queue_pointer)malloc(sizeof(queue));
 if(IS_FULL(temp)){
  fprintf(stderr,"the memory is full\n");
  exit(1);
 }
 temp->item=item;
 temp->link=NULL;
 if(*front){
  (*rear)->link=temp;
 }
 else{
  *front = temp;
}
  *rear = temp;
}

element deleteq(queue_pointer *front)
{
 queue_pointer temp = *front;
 element item;
 if(IS_EMPTY(*front)){
  fprintf(stderr,"the queue is empty\n");
  exit(1);
 }
 item=temp->item;
 *front=temp->link;
 free(temp);
 return item;
}




블로그 이미지

百見 이 不如一打 요 , 百打 가 不如一作 이다.

,