fork download
#include<stdio.h>
#include<stdlib.h>
#define QLEN 100
#define TRUE 1
#define FALSE 0
typedef int Data;
typedef struct _Qu
{
	int front;
	int rear;
	Data queArr[QLEN];
}Qu;

typedef Qu Queue;

void QInit(Queue *p);  //큐를 초기화 한다. 제일먼저 호출되야한다.

int QIsEmpty(Queue *p); //큐가 비었는지 아닌지 판단.True or False

void QPush(Queue *p, Data data); //큐에 데이터 저장.

Data QPop(Queue *p); //큐에서 가장 먼저 push 한 데이터를 이때 반환
//if (QIsEmpty(Queue *p)
//		printf("큐가 비었습니다.");
//		return false; //데이터가 하나  있는지 보장되야됨.

Data QPeek(Queue *p);//데이터 
//if (QIsEmpty(Queue *p)
//		printf("큐가 비었습니다.");
//		return false; //데이터가 하나  있는지 보장되야됨.


int main(void)
{
	Queue q;
	QInit(&q);
	
	QPush(&q,1);
	QPush(&q,3);
	while(QIsEmpty(&q)!=0)
		printf("%d",QPop(&q));
	return 0;
}

int NextPoint(int point)
{
	if(point==QLEN-1)
	return 0;
	else
	return point+1;
}
void QInit(Queue *p)
{
	p->front = 0; //0은 비워져 
	p->rear = 0;
}

int QIsEmpty(Queue *p)
{
	if(p->rear==p->front)
		return TRUE;
	else
		return FALSE;
}

void QPush(Queue *p,Data data)
{
	if(NextPoint(p->rear)==p->front)//다음을 가리키는것을 뽑아내야될 필요성.
		exit(-1);
	
	p->rear = NextPoint(p->rear); //하나 
	p->queArr[p->rear] = data;
}

Data QPop(Queue *p)
{
	if(QIsEmpty(&p)==1)
		exit(-1);
	printf("Empty not!");
	p->front=NextPoint(p->front);
	return p->queArr[p->front];
}

Data QPeek(Queue *p)
{
	int tmp=0;
	if(QIsEmpty(&p)==1)
		exit(-1);
	tmp = NextPoint(p->front);
	return p->queArr[tmp];
}
Success #stdin #stdout 0s 9296KB
stdin
Standard input is empty
stdout
Standard output is empty