기본 콘텐츠로 건너뛰기

5월, 2018의 게시물 표시

ch06 (maybe) CircularQueue

#include <stdio.h> #include <stdlib.h> #define MAX_QUEUE_SIZE 100 typedef int element; typedef struct { element queue[MAX_QUEUE_SIZE]; int front; int rear; }queryType; void error(char *message){ fprintf(stderr,"%s\n", message); exit(1); } void init(queryType *q) { q->front = q->rear = 0; } int isEmpty(queryType *q) { return (q->front == q->rear); } int isFull(queryType *q) { return ( (q->rear+1) % (MAX_QUEUE_SIZE) == q->front); //checking if front is ascended rear = means rear arrived to unused queue cell, full } void enqueue(queryType *q ,element item) { if(isFull(q)) { error("Queue is full\n"); } q->rear = (q->rear+1) % MAX_QUEUE_SIZE;//simply it means next cell q->queue[q->rear] = item; } element dequeue(queryType *q) { if(isEmpty(q))//get into the block if the result is true { error("Queue is empty\n"); } q->front = (q->front+1) % MAX_

Stack Practice Maze Escaping

#include <stdio.h>//5396952 이현민 #include <string.h> #include <stdlib.h> #define MAZE_SIZE 6 #define MAX_STACK_SIZE 100 typedef struct { short r; short c; } location; typedef struct { location stack[MAX_STACK_SIZE]; int top; }StackType; location here = {1,0}; location entry = {1,0}; //initiating entry and start point, those are containing garbage values char maze [MAZE_SIZE][MAZE_SIZE] = { { '1','1','1','1','1','1'}, { 'e','0','0','0','0','1'}, { '1','0','1','0','1','1'}, { '1','1','1','0','0','x'}, { '1','1','1','0','1','1'}, { '1','1','1','1','1','1'}, }; void init(StackType *s) { s->top = -1; } int isEmpty(StackType *s) { return (s->t