LittleDeveloper

Week11_그래프순회_BFS_실습 본문

알고리즘(C)

Week11_그래프순회_BFS_실습

lemonjelly 2021. 12. 3. 00:50

<원형큐> 필요

//큐 템플릿
#define SIZE 10

typedef struct{
	char elem[SIZE];
	int front, rear;
}QueueType;

void initQueue(QueueType* Q){
	Q->front = Q->rear = 0;
}

int isEmpty(QueueType* Q){
	return Q->rear == Q->front;
}

int isFull(QueueType* Q){
	return (Q->rear + 1) % SIZE == Q->front;
}

void enqueue(QueueType* Q, char vName){
	if (isFull(Q)){
		printf("FULL\n");
		return;
	}
	Q->rear = (Q->rear + 1) % SIZE;
	Q->elem[Q->rear] = vName;
}

char dequeue(QueueType* Q){
	if (isEmpty(Q)){
		printf("EMPTY\n");
		return 0;
	}
	Q->front = (Q->front + 1) % SIZE;
	return Q->elem[Q->front];
}

 

'알고리즘(C)' 카테고리의 다른 글

Week12_위상정렬_실습  (0) 2021.12.05
Week11_그래프순회_DFS_실습  (0) 2021.12.02
Week10_그래프_실습  (0) 2021.12.01
Week9_해시테이블_실습(2)  (0) 2021.11.29
Week9_해시테이블_실습(1)  (0) 2021.11.29