본문 바로가기

Programming

Node_Int : 연결된 큐를 위한 int형 클래스 + 연결 리스트로 구현된 리스트를 위한 노드 클래스 #pragma once#ifndef ___Node_Int#define ___Node_Int//Node_Int : 연결된 큐를 위한 int형 클래스 + 연결 리스트로 구현된 리스트를 위한 노드 클래스 #include class Node {Node*link;//다음 노드를 가리키는 포인터 변수int data;//노드의 데이터 필드public:Node(int val = 0) :data(val), link(NULL) {}Node* getLink() { return link; }void setLink(Node* next) { link = next; }void display() { printf(" ", data); }bool hasData(int val) { return data == val; } //자신의 다음에.. 더보기
ArrayList.h : 배열을 이용한 리스트 클래스 구현 #pragma once#ifndef ___ArrayList#define ___ArrayList//ArrayList.h : 배열을 이용한 리스트 클래스 구현 #include #include #define MAX_LIST_SIZE 100//오류 처리 함수inline void error(const char *message) {printf("%s\n", message);exit(1);} class ArrayList {int data[MAX_LIST_SIZE];//실제로 항목 값들이 들어감int length;//현재 리스트 내의 항목들의 개수public:ArrayList(void) { length = 0; }//생성자 ==> length을 초기화 //삽입 연산 : 리스트의 pos번째에 항목 e추가void inse.. 더보기
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 더보기