본문 바로가기

Programming/DS SorceCode

StudentQueue.h : 학생정보 큐 클래스 #pragma once#ifndef ___StudentQueue#define ___StudentQueue#include "Node_Student.h"//StudentQueue.h : 학생정보 큐 클래스 class StudentQueue {Node*front;//가장 먼저 삽입된 노드의 포인터Node* rear;//마지막에 삽입된 노드의 포인터public:StudentQueue() : front(NULL), rear(NULL) {}~StudentQueue() { while (!isEmpty()) delete dequeue(); }bool isEmpty() { return front == NULL; } //삽입 연산 : 연결된 큐의 맨 뒤에 노드 삽입void enqueue(Node* p) {if (isEmp.. 더보기
LinkedQueue.h : 연결된 큐 클래스 #pragma once#ifndef ___LinkedQueue#define ___LinkedQueue//LinkedQueue.h : 연결된 큐 클래스 #include "Node_Int.h"class LinkedQueue {Node_Int* front;//가장 먼저 삽입된 노드의 포인터Node_Int* rear;//마지막에 삽입된 노드의 포인터public:LinkedQueue() : front(NULL), rear(NULL) {}~LinkedQueue() { while (!isEmpty()) delete dequeue(); }bool isEmpty() { return front == NULL; } //삽입 연산 : 연결된 큐의 맨 뒤에 노드 삽입void enqueue(Node_Int* p) {if (isE.. 더보기
Node_Int : 연결된 큐를 위한 int형 클래스 #pragma once#ifndef ___Node_Int#define ___Node_Int//Node_Int : 연결된 큐를 위한 int형 클래스 #include class Node_Int {Node_Int*link;//다음 노드를 가리키는 포인터 변수int data;//노드의 데이터 필드public:Node_Int(int val = 0) :data(val), link(NULL) {}Node_Int* getLink() { return link; }void setLink(Node_Int* next) { link = next; }void display() { printf(" ", data); }};#endif // !___Node_Int 더보기
LinkedStack.h : 연결된 스택 클래스 구현 #pragma once#ifndef ___LinkedStack#define ___LinkedStack //LinkedStack.h : 연결된 스택 클래스 구현#include "Node_Student.h"//Node 클래스 포함class LinkedStack {Node*top;//헤드 포인터public:LinkedStack() { top = NULL; }//생성자~LinkedStack() { while (!isEmpty()) delete pop(); }//소멸자 - 현재의 연결 리스트에 동적으로 할당한 노드가 하나라도 있으면 모두 동적으로 해제해야 함.bool isEmpty() { return top == NULL; }void push(Node* p) {if (isEmpty()) top = p;else {.. 더보기
Node_Student.h : 연결된 스택을 위한 노드 클래스 구현 파일 #pragma once#ifndef ___Node_Student#define ___Node_Student //Node_Student.h : 연결된 스택을 위한 노드 클래스 구현 파일#include "Student.h"class Node : public Student {//Student를 상속하여 구현함.Node*link;//다음 노드를 가리키는 포인터 변수public:Node(int id = 0, const char* name = "", const char* dept = ""):Student(id, name, dept) {link = NULL;}//부모 클래스 Student의 생성자를 선택하여 호출한 것에 유의할 것. link는 반드시 NULL로 초기화해야 함.~Node(void) {}Node* getL.. 더보기
DynamicMemoryAllocation.h : int 형 2차원 배열 동적 할당 함수 #pragma once#ifndef ___DynamicMemoryAllocation#define ___DynamicMemoryAllocation#include //int 형 2차원 배열 동적 할당 함수int** alloc2DInt(int rows, int cols) {if (rows 더보기
BankSimulator.h : 은행 시뮬레이션 클래스 #pragma once#ifndef ___BankSimulator#define ___BankSimulator//BankSimulator.h : 은행 시뮬레이션 클래스 #include "CustomerQueue.h"class BankSimulator {int nSimulation;//입력 : 전체 시뮬레이션double probArrival;//입력 : 단위시간에 도착하는 평균 고객 수int tMaxService;//입력 : 한 고객에 대한 최대 서비스 시간int totalWaitTime;//결과 : 고객들이 기다린 전체시간int nCustomers;//결과 : 전체 고객 수int nServedCustomers;//결과 : 서비스 받은 고객 수CustomerQueue que;//고객 대기 큐 //랜덤 숫자를.. 더보기
CustomerQueue.h : 하나의 고객 정보를 관리하기 위한 클래스 #pragma once#ifndef ___CustomerQueue#define ___CustomerQueue //CustomerQueue.h : 하나의 고객 정보를 관리하기 위한 클래스//배열을 이용한 원형 큐 클래스 #include #include #define MAX_QUEUE_SIZE 100//오류 처리 함수inline void error(const char *message) {printf("%s\n", message);exit(1);} struct Customer {int id;//고객 번호int tArrival;//고객이 도착한 시간int tService;//이 고객의 서비스에 필요한 시간Customer(int i = 0, int tArr = 0, int tServ = 0):id(i), tArr.. 더보기