ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 원형큐_소수고리
    C연습 2021. 1. 17. 11:45
    #include <stdio.h>
    #include <stdlib.h>
    #define MAX_QUEUE_SIZE 16
    
    typedef int element;
    typedef struct {
    	element data[MAX_QUEUE_SIZE];
    	int front, rear;
    } QueueType;
    
    
    void error(char *message) {
    	fprintf(stderr, "%s\n", message);
    	exit(1);
    }
    
    void init_queue(QueueType *q) {
    	q->front = 0;
    	q->rear = 0;
    }
    
    int is_empty(QueueType *q) {
    	return (q->front == q->rear);
    }
    
    int is_full(QueueType *q) {
    	return (q->front == (q->rear + 1) % MAX_QUEUE_SIZE);
    }
    
    void enqueue(QueueType *q, element item) {
    	if (is_full(q))
    		error("큐가 포화상태입니다.");
    	q->rear = (q->rear + 1) % MAX_QUEUE_SIZE;
    	q->data[q->rear] = item;
    }
    
    element dequeue(QueueType *q) {
    	if (is_empty(q))
    		error("큐가 공백상태입니다.");
    	q->front = (q->front + 1) % MAX_QUEUE_SIZE;
    	return q->data[q->front];
    }
    
    void enqueue(QueueType *q) {
    	if (!is_empty(q)) {
    		int i = q->front;
    			do {
    				i = (i + 1) % MAX_QUEUE_SIZE;
    				printf("%d ", q->data[i]);
    				if (i == q->rear)
    					break;
    			} while (i != q->front);
    	}
    }
    
    void queuesize(QueueType *q) {
    	printf("큐가 가진 size: %d", (q->rear - q->front) % MAX_QUEUE_SIZE);
    }
    
    int frontqueue(QueueType *q) {
    	if (is_empty(q))
    		return -1;
    	printf("%d", q->data[q->front]);
    }
    
    int backqueue(QueueType *q) {
    	if (is_empty(q))
    		return -1;
    	printf("%d", q->data[q->rear]);
    }
    
    int main() {
    	QueueType queue;
    	int Element;
    	char check[10];
    
    	scanf_s("%d", &Element);
    	if (Element <= 10000 || Element >= 1) {
    		for (int i = 0; i < Element; i++)
    		{
    			scanf("%s", &check);
    			switch (check)
    			{
    				case ""
    			}
    		}
    	}
    	else return 0;
    
    }

    'C연습' 카테고리의 다른 글

    queue  (0) 2021.01.17
    이진 검색 트리  (0) 2021.01.17
    연결 리스트  (0) 2021.01.17
    stack 괄호 짝 맞추기  (0) 2021.01.17
    stack  (0) 2021.01.17

    댓글

Designed by Tistory.