キュー
キュー(queue)は、FIFO(First In First Out)、先入れ先出しのデータ構造 を持つ。 以下のように、キューに文字列と数値からなる複数人のデータを順次格納し、 また、順次取り出す関数群を作成したい。 このとき、以下の3つの関数を作成しなさい。
  1. データ d を、キューに加える関数 int put_queue(Queue *q, Data *d)
  2. キューから取り出す関数 Data *get_queue(Queue *q)
    とりだしたあとの q.data[i] には、NULL を書き込んでおくこと。
  3. キューの初期化を行う関数 int ini_queue(Queue *q) も作成すること。
    初期化の際は、q.data[MAX_SIZE] のすべてに NULL を代入して初期化すること。
以下のものはすでに作成済み:
#include  <stdio.h>

#define MAX_SIZE 5

typedef struct d_tab{
  char name[10];
  int age;
} Data;

typedef struct q_tab {
  Data *data[MAX_SIZE];
  int  head;   // データの先頭
  int  tail;  // データの最後
  int data_num; // 格納データ数
} Queue;

int ini_queue(Queue *q);
Data *get_queue(Queue *q);
int  put_queue(Queue *q, Data *d);
int  print_queue(Queue *q);
int  check_queue(Queue *q);
int  check_func();

int main(){
  int i;

  check_func();

}
int check_func(){
  int i;
  Data  rdata[10] = {
    "yamada" ,  23,
    "yoshida" ,  20,
    "hara" ,  33,
    "kida" ,  19,
    "yokoama" ,  29,
    "uda" ,  11,
    "iida" ,  28,
    "toda" ,  21,
    "matsu" ,  35,
    "ishida" ,  13,
  };
  Queue q;
  
  ini_queue(&q);
  //  check_queue(&q);
  print_queue(&q);
  for(i=0; i<10; i++){
    if( put_queue(&q, &rdata[i]) == 1){
      //      check_queue(&q);
      print_queue(&q);
    }else{
      printf("Queue is full!\n");
    }
    if( i!=0 && i%3 == 0){
      printf("get %d\n",(get_queue(&q))->age);
      //      check_queue(&q);
      print_queue(&q);
    }
  } 
}
// queue q の q.data[MAX_SIZE]のNULLによる初期化、q.head, q.tail, data_num
// の初期化関数
int ini_queue(Queue *q){
}

int print_queue(Queue *q){
  int i, j;
  
  if(q->data_num < 1){
    printf("NULL\n");
  }else{
    printf("\n[");
    for(j=q->head, i=0; idata_num; i++, j=(j+1)%(MAX_SIZE)){
      printf("%d:%s\n", q->data[j]->age, q->data[j]->name);
    }
    printf("]\n");
  }
}

int check_queue(Queue *q){
  int i;
  
  if(q->data_num < 1){
    printf("NULL");
  }else{
    printf("|");
    for(i=0; i<(MAX_SIZE); i++){
      if(q->data[i] != NULL ){
	printf("%d|", q->data[i]->age);
      }else{
	printf("00|");
      }
    }
  }
  printf("q=%d, h:%d t:%d", q->data_num, q->head, q->tail);
  printf("\n");

}

// queue q からデータを取り出し、そのデータへのポインタを
// 関数の返り値として返す関数
Data *get_queue(Queue *q){

}

// queue q へデータ dを格納し、成功なら 1,
// 失敗な 0 を返す関数

int put_queue(Queue *q, Data *d){

}