(자료구조)Queue - 배열
프로그래밍/학교과제 2019. 3. 3. 16:59
큐(QUEUE) 기본 설계 - 배열 버전
배열의 제일 첫 번째는 시작점으로 데이터가 들어가지 않는다.
실제로 데이터가 채워지는 곳은 배열의 전체 크기에 -1이다.
Front, Rear, Data 값의 흐름을 표현한것이다.
Queue의 Empty와 Full 값을 확인하는 방법이다.
큐(QUEUE) 기본 규현- 배열 버전
dequeue 함수
1
2
3
4
5
6
7
8
9
10
void dequeue(int* queue) {
if (!IsEmpty()) {
printf("data does not exist\n");
return;
}
printf("%d is delete", queue[Front + 1]);
queue[Front + 1] = -1; //데이터 삭제
Front++;
}
Colored by Color Scripter
cs- enqueue 함수
1
2
3
4
5
6
7
8
9
10
11
void enqueue(int* queue) {
if (Rear+1 == Max_Size) { //rear+1 == 배열크기 >>
printf("data is Full\n");
}
else {
Rear++;
printf("input the data : ");
scanf_s("%d", &queue[Rear]);
}
}
}
Colored by Color Scripter
cs- 기타함수 선언
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
void Init() { //초기화 단계
Front = 0;
Rear = 0;
}
void front(int* queue) { //제일 앞에 값 확인
if (!IsEmpty())
return;
printf("front is %d.\n", queue[Front + 1]);
}
void rear(int* queue) { //제일 뒤에 값 확인
if (!IsEmpty(queue))
return;
printf("rear is %d.\n", queue[Rear]);
}
bool IsEmpty() {
if (Front == Rear) { //큐의 비어있는 여부 확인
return false;
}
else {
return true;
}
}
Colored by Color Scripter
cs공유하기
게시글 관리
구독하기아시라우'프로그래밍 > 학교과제' 카테고리의 다른 글
(자료구조)이중연결리스트 (0)2019.03.05(자료구조)Queue - 원형큐 (0)2019.03.03(자료구조)Queue (0)2019.03.01(자료구조)Stack (0)2019.02.28TAG
c언어, 알고리즘, 원형큐, 자료구조, 자료구조 Queue, 큐
관련글 관련글 더보기
- (자료구조)이중연결리스트
- (자료구조)Queue - 원형큐
- (자료구조)Queue
- (자료구조)Stack
댓글 0
댓글 접기 댓글 펼치기이전 댓글 더보기
댓글
비밀글
등록