학교 과제 12

c++로 작성한 지하철 노선도 최단거리 찾기

자료구조 프로그래밍 과목을 배우면서 c++로 작성한 지하철 노선도 최단거리 찾기 프로그램입니다.(string 클래스는 사용하지 말라고 했습니다) 위와 같은 지하철 노선도가 존재할 때(a노선, b노선, c노선) 출발역과 도착역을 입력했을 경우 최단경로와 소요 시간을 출력하는 프로그램을 작성했습니다.(좌표가 같을 경우 환승(30초 소요), 같은 노선 내 이동하면 한 역당 1분 소요) metro.h#include #include //경로 위해using namespace std; #define MAX 43 //20+10+13#define INF 9999 class Station{private: char line; //각 노선 구분 짓기 위해 int num; //역 이름 int x, y; //좌표public: S..

학교 과제 2018.01.07

c++로 작성한 최대 힙

자료구조 프로그래밍 과목을 배우면서 c++로 작성한 최대힙입니다. maxheap.h#include using namespace std; template class Maxheap{private: T *heap; //힙 배열 int heapSize; //힙에 있는 요소 수 int capacity; //힙의 크기 void ChangeSize1D(T *&a, const int oldSize, const int newSize) { if(newSizenewSize?newSize:oldSize; //min(oldSize, newSize) copy(a, a+number, temp); delete []a; a=temp; }public: Maxheap(int theCapacity=10) { if(theCapacity

학교 과제 2018.01.06

c++로 작성한 AVL 트리

자료구조 프로그래밍 과목을 배우면서 c++로 작성한 AVL 트리입니다. avl.h#include #include using namespace std; struct Node{ int data, bf; //bf=balance factor Node *leftChild, *rightChild; Node(int element, Node *left = 0, Node *right = 0) :data(element), bf(0), leftChild(left), rightChild(right) { }}; class AVL{private: Node *root; void Insert(Node *&ptr, int element) { if (ptr == 0) ptr = new Node(element); else if (elem..

학교 과제 2018.01.05

c++로 작성한 이진탐색트리

자료구조 프로그래밍 과목을 배우면서 c++로 작성한 이진탐색트리입니다. bst.h#ifndef BST_H#define BST_H #include #include #include using namespace std; template struct Node{ Node(K ky, E el, Node *left = 0, Node *right = 0) :key(ky), element(el), leftChild(left), rightChild(right) { } Node *leftChild; K key; E element; Node *rightChild;}; template class BST{private: void Visit(Node *); void Insert(Node*&, K &, E &); void Delet..

학교 과제 2018.01.05

c++로 작성한 트리 순회

자료구조 프로그래밍 과목을 배우면서 c++로 작성한 트리 순회입니다.(2가지 버전) bt.h#ifndef TREE_H#define TREE_H#include #include using namespace std; template struct Node{ Node(T d, Node *left = 0, Node *right = 0) :data(d), leftChild(left), rightChild(right) { } Node *leftChild; T data; Node *rightChild;}; template class Tree{private: void Visit(Node *); void Insert(Node *&, T &); void Preorder(Node *); void Inorder(Node *); ..

학교 과제 2018.01.02

c++로 작성한 링크드 리스트

자료구조 프로그래밍 과목을 배우면서 c++로 작성한 링크드 리스트입니다. list.h#include using namespace std; struct Node{ int data; Node *link; Node(int d = 0, Node *l = 0) :data(d), link(l) { }}; struct IntList{ Node *first; //첫 노드를 가리킴 Node *last; //마지막 노드를 가리킴 IntList() { last = first = 0; } void Push_Back(int); //리스트 뒤에 삽입 void Push_Front(int); //리스트 앞에 삽입 void Insert(int); //정렬되어 있다는 가정 하에 void Delete(int); //리스트의 원소 삭제 b..

학교 과제 2018.01.02

c++로 작성한 후위연산 계산기

자료구조 프로그래밍 과목을 배우면서 c++로 작성한 Postfix Calculator입니다. post.h#ifndef POSTFIX_H#define POSTFIX_H #include using namespace std; #define ID 257#define NUM 258#define EQ 259#define NE 260#define GE 261#define LE 262#define AND 263#define OR 264#define UMINUS 265 #define MAXLEN 80 struct Expression{ char *str; int pos; int len; Expression(char *s) :str(s), pos(0) { for (len = 0; str[len] != '\0'; len++)..

학교 과제 2017.12.29

c++로 작성한 간단한 행렬 클래스

자료구조 프로그래밍 과목을 배우면서 c++로 작성한 간단한 행렬 클래스입니다.(2가지 버전) 2*2 행렬 클래스matrixa.h#ifndef MATRIX_H#define MATRIX_H #include using namespace std; class Matrix{private: int m[2][2];public: Matrix(int a = 0, int b = 0, int c = 0, int d = 0); ~Matrix() { } void ShowMatrix(); Matrix Transpose(); Matrix operator+(const Matrix &a); Matrix operator-(const Matrix &a); Matrix operator*(const Matrix &a); void operato..

학교 과제 2017.12.26

c++로 작성한 간단한 다항식 클래스

자료구조 프로그래밍 과목을 배우면서 c++로 작성한 간단한 다항식 클래스입니다.(2가지 버전) polya.h#ifndef POLYNOMIAL_H#define POLYNOMIAL_H #include using namespace std; class Polynomial; //전방참조 class Term{private: float coef; //coefficient int exp; //exponent friend class Polynomial; friend ostream &operator(istream &, Polynomial &);}; class Polynomial{private: Term *termArray; int capacity; //1로 초기화 int terms; //저장된 항의 수로 0으로 초기화pu..

학교 과제 2017.12.24