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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <stdio.h> #include <stdlib.h> #define MAXX 10001 struct Queue { int front, back; int array[MAXX]; }; int isFull( struct Queue *q) { int tmp = (q->back+1)%MAXX; if (tmp == q->front) return 1; return 0; } int isEmpty( struct Queue *q){ if (q->back == q->front) return 1; return 0; } void push( struct Queue* q, int data) { if (isFull(q)) return ; q->back = (q->back+1) % MAXX; q->array[q->back] = data; } int pop( struct Queue *q) { if (isEmpty(q)) return -1; q->front = (q->front+1)%MAXX; return q->array[q->front]; } int peek( struct Queue *q){ if (isEmpty(q)) return -1; return q->array[q->front]; } int main() { struct Queue *q = ( struct Queue*) malloc ( sizeof ( struct Queue)); for ( int i =1; i <= 7; i++) { push(q, i); } while (!isEmpty(q)) { printf ( "%d" , pop(q)); } free (q); } |
'Computer Science' 카테고리의 다른 글
[자료구조] qsort, quick sort 구현하기 (0) | 2020.03.24 |
---|---|
10진수 -> 16진수/ 16진수 -> 10진수 C언어로 구현하기 (0) | 2020.03.24 |
[자료구조] 연결리스트(Linked List) (0) | 2020.03.23 |
[자료구조] 연결리스트(Linked List) 배열로 구현하기 (0) | 2020.03.23 |
파스칼의 삼각형 (0) | 2020.02.07 |