본문 바로가기

분류 전체보기15

[큐 코드] //큐 #include #include using namespace std; #define MAX_QUEUE_SIZE 100 class CircularQueue { protected: int front; int rear; int data[MAX_QUEUE_SIZE]; public: CircularQueue() { front = rear = 0; } bool isEmpty() { return front == rear; } bool isFull() { return (rear + 1) % MAX_QUEUE_SIZE == front; } int empty() { if (front == rear) return 1; else return 0; } void enqueue(int val); int dequeue(); .. 2023. 4. 15.
[스택 코드] //알파벳 // Alphabet #include using namespace std; #define MAX_STACK_SIZE 20 inline void error(char* message) { cout = 0; i--) cout ch; for (char c = max+1; c < ch; c++) { // max부터 현재 입력 데이터 바로 이전 알파벳까지 push s.push(c); pm[index++] = '+'; // 추후 출력을 위해 '+'를 배열에 저장 } if (s.isEmpty() || ch != s.peek()) { // 현재 입력 데이터가 스택 top 데이터와 다른 경우 push if (s.isItem(ch)) { // 현재 입력 데이터가 이미 스택에 pop할 수 없는 위치에 있으면 NO .. 2023. 4. 15.
[클래스 코드] //내 코드 #include using namespace std; class Rectangle { private: int width; int height; public: Rectangle(); Rectangle(int, int); int evalArea(int, int); int evalPerimeter(int, int); }; Rectangle::Rectangle(int w, int h) { width = w; height = h; } int Rectangle::evalArea(int width, int height) { int area = width * height; return area; } int Rectangle :: evalPerimeter(int width, int height) { int .. 2023. 4. 15.
[Chap5] 연결 리스트 과제 문제 ) 교재에 있는 LinkedQueue를 Dequeue로 상속한다음, 앞에서추가하는 함수, 뒤에서 삭제하는 함수 를 추가하도록 고친다. 그리고, 앞에서 2번째 노드를 제거하고 1번째와 3번째 노드를 연결하는 메소드인 delete2nd를 추가한다. 이때, 3번째 노드가 없는 경우에는 NO를 출력한다. #include using namespace std; class Node { private: int data; Node* link; public: Node(int val = 0) : data(val),link(NULL) {} Node* getLink() { return link; } void setLink(Node* next) { link = next; } void display() { cout getLi.. 2023. 4. 6.