Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Selenium
- paramiko
- pip
- 기타 연주
- 핑거스타일
- ubuntu
- Python
- OpenCV
- pytorch
- C
- C#
- error
- pandas
- 프로그래머스
- label
- C++
- mysql
- windows forms
- 채보
- Visual Studio
- JSON
- Docker
- SSH
- Linux
- 오류
- Numpy
- nvidia-smi
- VS Code
- YOLO
- 컨테이너
Archives
- Today
- Total
기계는 거짓말하지 않는다
원형 큐(Circular Queue) 본문
element 한 자리가 항상 비게되지만, 재정렬 없이 큐 이용이 가능하다.
First In First Out(FIFO) 구조
#include <stdio.h> #define MAX_Q_SIZE 11 // 원형 큐 이용 가능 크기 MAX_SIZE - 1 typedef enum eSelectMenu { selectAdd = 1, selectDelete, selectPrint, selectExit } eSelectMenu; typedef enum eBool { false, true } eBool; void Add(int [], int*, int*, int); int Delete(int [], int*, int*); eBool IsEmpty(int, int); eBool IsFull(int, int); int main(void) { int queue[MAX_Q_SIZE]; int rear, front, data, i; eSelectMenu select; if (MAX_Q_SIZE < 2) { fprintf(stderr, "Queue size error\n"); return 0; } else { rear = 0; front = 0; } while (1) { printf("1. add / 2. delete / 3. print / 4. exit\n"); printf("select: "); scanf_s("%d", &select); switch (select) { case selectAdd: if (IsFull(front, rear) == true) { printf("Queue Full\n\n"); break; } printf("data: "); scanf_s("%d", &data); Add(queue, &front, &rear, data); printf("\n"); break; case selectDelete: if (IsEmpty(front, rear) == true) { printf("Queue Empty\n\n"); break; } printf("return data: %d\n\n", Delete(queue, &front, &rear)); break; case selectPrint: printf("\n< Print >\n"); printf("front: %d, rear: %d\n", front, rear); if (IsEmpty(front, rear) == true) printf("Qeueu Empty"); else { for (i = (front + 1) % MAX_Q_SIZE; i != (rear + 1) % MAX_Q_SIZE; i = (i + 1) % MAX_Q_SIZE) printf("%d ", queue[i]); } printf("\n\n"); break; case selectExit: printf("Exit Program\n"); return 0; default: printf("re\n\n"); } while (getchar() != '\n') {} } } void Add(int queue[], int * front, int * rear, int data) { *rear = (*rear + 1) % MAX_Q_SIZE; queue[*rear] = data; } int Delete(int queue[], int * front, int * rear) { int data; *front = (*front + 1) % MAX_Q_SIZE; data = queue[*front]; return data; } eBool IsFull(int front, int rear) { return (rear + 1) % MAX_Q_SIZE == front ? true : false; } eBool IsEmpty(int front, int rear) { return rear == front ? true : false; }

'C' 카테고리의 다른 글
이중 연결 리스트(Doubly Linked List) (0) | 2021.04.25 |
---|---|
링크드 리스트(Linked List) (0) | 2020.12.12 |
스택(Stack) (0) | 2020.12.09 |
Short Circuit Evaluation(SCE, 단축 평가) (0) | 2020.12.06 |
C언어 키워드 (0) | 2020.12.05 |