1. 큐
- 큐는 '줄을 서서 기다리다' 라는 뜻을 가지고 있다.
- 큐는 선입선출 (FIFO : First In, First Out)원리의 자료구조이다.
- 큐 구조는 컴퓨터 과학 전반에 자주 쓰이는 자료구이다. 예) 버퍼
2. queue 함수
- void inqueue(int *,int); // 큐에 데이터를 삽입하는 연산
- int dequeue(int *); // 큐에서 데이터를 빼는 연산
3. 소스
- #include <stdio.h>
- int front = -1;
- int rear;
- void inqueue(int *,int); // 큐에 데이터를 삽입하는 연산
- int dequeue(int *); // 큐에서 데이터를 빼는 연산
- int main(void)
- {
- int arr[10] = {0,};
- inqueue(arr,10);
- inqueue(arr,20);
- inqueue(arr,30);
- inqueue(arr,40);
- inqueue(arr,50);
- inqueue(arr,60);
- inqueue(arr,70);
- inqueue(arr,80);
- inqueue(arr,90);
- inqueue(arr,100);
- return 0;
- }
- void inqueue(int *queue, int data)
- {
- if(rear == 9)
- else
- {
- (*(queue + (rear++))) = data;
- }
- }
- int dequeue(int * queue)
- {
- int data;
- if((front+1) == rear)
- {
- return 0;
- }
- else
- {
- data = (*(queue+(++front)));
- return data;
- }
- }
4. 결과화면
'c언어(알고리즘)' 카테고리의 다른 글
너비우선탐색(BFS : Breadth First Search) (0) | 2016.11.08 |
---|---|
깊이우선탐색(DFS : Depth First Search) (0) | 2016.11.01 |
스택(Stacks) - 연결리스트로 구현(The implementation with the linked lists) (0) | 2016.11.01 |
스택(Stacks) - 배열로 구현(The implementation with the array) (0) | 2016.11.01 |
힙 정렬 (Heap-Sort) (0) | 2016.11.01 |