본문 바로가기

Programming/DS SorceCode

CircularDeque.h : CircularQueue 클래스를 상속해서 구현한 원형 덱 클래스 #pragma once#ifndef ___CircularDeque#define ___CircularDeque //CircularDeque.h : CircularQueue 클래스를 상속해서 구현한 원형 덱 클래스#include "CircularQueue.h" class CircularDeque : public CircularQueue {public:CircularDeque(){}void addRear(int val) { enqueue(val); }//enqueue() 호출int deleteFront() { return dequeue(); }//dequeue() 호출int getFront() { return peek(); }//peek() 호출void addFront(int val) {//전단에 삽입if (.. 더보기
ArrayStack.h : 배열을 이용한 int 스택 클래스 #pragma once//ArrayStack.h : 배열을 이용한 int 스택 클래스#ifndef ___ArrayStack#define ___ArrayStack #include #include //오류 처리 함수inline void error(const char *message) {printf("%s\n", message);exit(1);} const int MAX_STACK_SIZE = 20;//스택의 최대 크기 설정class ArrayStack {int top;//요소의 개수int data[MAX_STACK_SIZE];//요소의 배열public:ArrayStack() { top = -1; }//스택 생성자(ADT의 create()역할)~ArrayStack() {}//스택 소멸자bool isEmpty(.. 더보기
CircularQueue.h : 배열을 이용한 원형 큐 클래스 #pragma once//배열을 이용한 원형 큐 클래스#ifndef ___CircularQueue#define ___CircularQueue #include #include #define MAX_QUEUE_SIZE 100//오류 처리 함수inline void error(const char *message) {printf("%s\n", message);exit(1);} class CircularQueue {protected:int front;//첫 번째 요소 앞의 위치int rear;//마지막 요소 위치int data[MAX_QUEUE_SIZE];//요소의 배열public:CircularQueue() { front = rear = 0; }bool isEmpty() { return front == rear;.. 더보기
Location2D.h : 위치 정보를 나타내는 구조체 #pragma once#ifndef ___Location2D#define ___Location2D struct Location2D {int row;//현재 위치의 행 번호int col;//현재 위치의 열 번호Location2D(int r = 0, int c = 0) { row = r; col = c; }//위치 p가 자신의 이웃인지 검사하는 함수bool isNeighbor(Location2D &p) {return ((row == p.row && (col == p.col - 1 || col == p.col + 1))|| (col == p.col &&row == p.row - 1 || row == p.row + 1));}//위치 p가 자신과 같은 위치인지를 검사하는 함수(연산자 오버로딩)bool operat.. 더보기
OperandStack.h : 피연산자 스택 클래스 #pragma once//OperandStack.h : 피연산자 스택 클래스#ifndef ___OperandStack#define ___OperandStack #include #include const int MAX_STACK_SIZE = 20;//스택의 최대 크기 설정 //오류 처리 함수inline void error(const char *message) {printf("%s\n", message);exit(1);}class OperandStack {double data[MAX_STACK_SIZE];//요소의 배열int top;//요소의 개수public:OperandStack() { top = -1; }//스택 생성자bool isEmpty() { return top == -1; }bool isFull(.. 더보기
StudentStack.h : 학생정보 스택 클래스 #pragma once//StudentStack.h : 학생정보 스택 클래스#ifndef ___StudentStack#define ___StudentStack #include "Student.h"const int MAX_STACK_SIZE = 100;//스택의 최대 크기 설정//오류 처리 함수inline void error(const char *message) {printf("%s\n", message);exit(1);} class StudentStack {int top;//요소의 개수Student data[MAX_STACK_SIZE];//요소의 배열public:StudentStack() { top = -1; }//스택 생성자bool isEmpty() { return top == -1; }bool isF.. 더보기
Student.h : 학생 정보를 나타내는 클래스 //Student.h : 학생 정보를 나타내는 클래스 #ifndef ___Student#define ___Student#include #include #include #define MAX_STRING 100 class Student {int id;//학번char name[MAX_STRING];//이름char dept[MAX_STRING];//소속 학과public:Student(int i = 0, const char* n = " ",const char* d = " ") { set(i, n, d); }void set(int i, const char* n, const char* d) {id = i;strcpy_s(name, n);//문자열 복사 함수strcpy_s(dept, d);//문자열 복사 함수}void.. 더보기