본문 바로가기
학교생활!

[230330]자료구조 과제3: Print

by Daybreak21 2023. 4. 2.

자료구조 3주차 : 스택과 큐 과제

교수님이 제시해주신 스켈레톤 코드를 채워넣는 과제였다. 

*백준 스택문제 링크 넣기 

 

※문제설명

  • . 프린터가 있다고 가정하자. 이 프린터는 사용자에게 프린트 인쇄 요청을 받고 이를 순서대로 저장한 뒤 최종적으로 출력해준다. 
  • 그러나 사용자가 인쇄 요청을 보내고 출력을 시작하기 전까지 사용자의 인쇄 요청 취소를 반영해야 한다
  • 각 요청마다 중요도(imp)와 페이지 수(pages)가 있고 이를 비교하여 제일 빨리 처리해야 하는 요청을 먼저 인쇄한다 (중요도가 높을 수록, 페이지 수가 많을 수록 먼저 인쇄한다.) 
  • 이러한 작업을 위해 우리는 배열을 사용한 스택과 원형큐를 사용할 것이다.

※구현할 코드  

InputPrintStack 클래스

더보기

⦁ Int형 top

⦁ Print형 배열 data (사이즈는 MAX_INPUT_SIZE)
⦁ 기본 생성자 및 소멸자
⦁ bool isEmpty(): 스택이 공백상태인지 확인. 공백이면 참, 아니면 거짓을 반환한다.
⦁ bool isFull(): 스택이 포화상태인지 확인. 포화이면 참, 아니면 거짓을 반환한다.
⦁ void push(Print x): 인수인 Print형의 매개 변수 x를 스택에 삽입한다.
⦁ Print pop(): 스택 상단의 요소를 반환한고 삭제한다.
⦁ void display(): 요소가 존재하는지 확인 한 후 모든 Print 형의 요소의 user 변수를 프린트한다.    예) Stack: Name1, Name2, Name3, Name4

 

OutputPrintStack 클래스

더보기

⦁ Int형 front 및 rear
⦁ Print형 배열 data (사이즈는 MAX_INPUT_SIZE)
⦁ 기본 생성자 및 소멸자
⦁ bool isEmpty(): 원형큐가 공백상태인지 확인. 공백이면 참, 아니면 거짓을 반환한다.
⦁ bool isFull(): 원형큐가 포화상태인지 확인. 포화이면 참, 아니면 거짓을 반환한다.
⦁ void enqueue(Print x): 인수인 Print형의 매개 변수 x를 원형큐에 삽입한다.
⦁ Print dequeue(): 원형큐의 전단(front)의 요소를 반환한고 삭제한다.
⦁ void display(): 요소가 존재하는지 확인 한 후 모든 Print 형의 요소의 user 변수를 프린트한다.     예) Queue: Name1, Name2, Name3, Name4

 

PrintSim 클래스

더보기

⦁ InputPrintStack형의 input
⦁ OutputPrintQueue형의 output
⦁ void insertInputPrints(Print x):  input이 포화상태가 아니라면 인수로 받은 Print형의 x를input에 삽입한다.
⦁ void removePrintJob(): 직전에 들어온 인쇄 요청을 삭제한다.즉input에 들어온 Print 요소를 삭제한다.
⦁ int compareImportance(Print a, Print b): 인수로 받는 Print형의 a와 b의 중요도(imp)를 비교한다. a의 중요도가 더 낮다면 -1, a와 b의 중요도가 같다면 1, a의 중요도가 더 높다면 0을 반환한다.
⦁ int comparePages(Print a, Print b): 인수로 받는 Print형의 a와 b의 페이지 수(pages)를 비교한다. a의 페이지 수가 더 적다면 -1, 크다면 1을 반환한다. (그 외의 케이스는 다루지 않아도 된다.)
⦁ void movePrintsToOutputQueue(): input에 있는 Print형의 요소들을 모두 output에 옮긴다.
⦁ void outputPrintsByImportance(): output 원형큐의 시작부터 끝까지 순서대로 체크하며 제일 높은 중요도를 가진 Print형의 요소를 먼저 삭제한 후 해당 요소의 user를 화면상에 출력한다. 만약 현재 요소들 중 중요도가 가장 높지만 동시에 동일한 중요도를 가진 다른 요소가 있을 경우 페이지 수가 더 많은 요소를 먼저 삭제한 후 해당 요소의 user를 화면상에 출력한다. Output 큐가 공백상태가 될때까지 반복한다. 원형큐의 선입선출의 특성과 enqueue, dequeue를 이용하여 구현하라. (힌트: 만약 dequeue한 요소가 아직 인쇄될 순서가 아니라면 다시 output에 enqueue하라.)
⦁ void displayInput(): input 스택의 요소들을 모두 출력한다.
⦁ void displayOutput(): output 큐의 요소들을 모두 출력한다.

 

main함수

더보기
int main() {
    PrinterSim sim;

    sim.insertInputPrints(Print("A", 1, 5));
    sim.insertInputPrints(Print("B", 2, 13));
    sim.insertInputPrints(Print("C", 3, 3));
    sim.insertInputPrints(Print("D", 4, 15));
    sim.insertInputPrints(Print("E", 5, 10));
    sim.removePrintJob();
    sim.insertInputPrints(Print("F", 2, 10));
    sim.removePrintJob();
    sim.insertInputPrints(Print("G", 3, 10));
    sim.removePrintJob();
    sim.insertInputPrints(Print("H", 4, 20));
    sim.insertInputPrints(Print("I", 5, 20));
    sim.insertInputPrints(Print("J", 4, 18));
    sim.insertInputPrints(Print("K", 1, 20));
    sim.removePrintJob();
    sim.insertInputPrints(Print("L", 4, 10));
    sim.insertInputPrints(Print("M", 5, 19));
    sim.insertInputPrints(Print("N", 2, 19));
    sim.removePrintJob();
    sim.insertInputPrints(Print("O", 1, 19));
    sim.insertInputPrints(Print("P", 1, 18));
    sim.removePrintJob();
    sim.insertInputPrints(Print("Q", 3, 18));
    sim.insertInputPrints(Print("R", 4, 19));
    //인쇄 요청 끝

    sim.displayInput();
    sim.movePrintsToOutputQueue();
    sim.displayOutput();
    sim.outputPrintsByImportance();
    //인쇄 요청 처리 끝

    return 0;

}

 

완성된 화면


 

class Print { }

class Print {
private:
    char user[10];
    int imp; // 중요도는 1 to 5 까지만 가능
    int pages; //페이지수는 1 to 20 까지만 가능

public:
    Print() { } // 기본 생성자
    Print(const char* u, int i, int p) { // 매개 변수가 있는 생성자
        strcpy(user, u);
        imp = i;
        pages = p;
    }
    ~Print() {} // 소멸자

    char* getUser() { // user를 반환
        return user;
    }

    int getImp() { // imp(중요도)를 반환
        return imp;
    }

    int getPages() { // pages(페이지 수)를 반환
        return pages;
    }

    void setImp(int i) { // imp(중요도)를 설정
        imp = i;
    }

    void setPages(int p) { // pages(페이지 수)를 설정
        pages = p;
    }
};
Print 클래스를 교수님께서 제시해주어 내가 작성할 코드는 없었다.



 

 

class InputPrintStack { } *스택 구현

class InputPrintStack {
private:
    int top;
    Print data[MAX_INPUT_SIZE];
public:
    InputPrintStack() { top = -1; }
    ~InputPrintStack() {}
    bool isEmpty() { return top == -1; }
    bool isFull() { return top == MAX_INPUT_SIZE - 1; }

    void push(Print x) {
        if (isFull()) error("스택 포화 에러");
        data[++top] = x;
    }

    Print pop() {
        if (isEmpty()) error("스택 공백 에러");
        return data[top--];
    }

    Print peek() {
        if (isEmpty()) error("스택 공백 에러");
        return data[top];
    }

    void display() {
        cout << " Stack: ";
        for (int i = 0; i <= top; i++) cout << data[i].getUser() << " ";
        cout << endl;
    }
   
    int getTop() { return top; }
};

 -생성자로 Stack의 상단을 가르키는 top변수를 -1로 초기화 해주었다. 

-push, pop, peek를 실행하기 전에 스택이 적절한 상태인지 검사하기 위한 isEmpty함수와 isFull함수를 작성하였다. 

-push() : 매개변수로 받은 Print타입의 값을 스택(data배열)상단(변수 top값에 1을 더한 인덱스)에 넣어주었다. 

-pop() : 맨 위에 있는 배열의 값을 리턴하고 스택에서 값이 삭제된것처럼 보이기 위해 top에서 1을 빼준다. 

-peek() : 맨 위에 있는 값을 보여주는 함수

-display() : data배열을 0부터 top까지 돌면서 값들을 출력한다. 이때 출력하는 값은 Print형의 요소의 user변수이기 때문에 data[i].getUser()  함수를 사용하여 private로 보호되있는 변수를 가져왔다. 

-getTop() : movePrintsToOutputQueue()함수를 쓸 때에 반복문의 반복횟수를 설정해주기 위해 top(=size-1)을 반환하는 함수이다. top은 private로 다른 클래스에서 접근하지 못하기 때문에 getTop()함수를 만들어 값을 사용할 수 있게 하였다. 

 

class OutputPrintQueue{ } *원형큐 구현

class OutputPrintQueue {
public:
    int front;
    int rear;
    Print data[MAX_INPUT_SIZE];
public:
    OutputPrintQueue() { front = rear = 0; }
    ~OutputPrintQueue() {}
    bool isEmpty() { return front == rear; }
    bool isFull() { return (rear + 1) % MAX_INPUT_SIZE == front; }

    void enqueue(Print x) {
        if (isFull()) error(" error: 큐가 포화상태입니다.\n");
        else {
            rear = (rear + 1) % MAX_INPUT_SIZE;
            data[rear] = x;
        }
    }

    Print dequeue() {
        if (isEmpty()) error(" error: 큐가 공백상태입니다.\n");
        else {
            front = (front + 1) % MAX_INPUT_SIZE;
            return data[front];
        }
    }

    Print peek() {
        if (isEmpty()) error(" error: 큐가 공백상태입니다.\n");
        else {
            return data[(front + 1) % MAX_INPUT_SIZE];
        }
    }

    void display() {
        cout << " Queue: ";
        int maxi = (front < rear) ? rear : rear + MAX_INPUT_SIZE;
        for (int i = front + 1; i <= maxi; i++) cout << data[i % MAX_INPUT_SIZE].getUser() << " ";
        cout << endl;
    }
    //outputPrintsByImportance()에서 반복문횟수를 정하기 위한 size값을 함수로 넘겨줌
    int getSize() {
        int maxi = (front < rear) ? rear : rear + MAX_INPUT_SIZE;
        return maxi-front;
    }

};

 

-생성자로 큐의 전단을 가르키는 front와 후단을 가르키는 rear을 0으로 초기화해준다.  큐의 제일 앞에 있는 값이 빠질때  front값을 +1로 옮겨주어 배열에 있는 항목들을 전단쪽으로 모두 이동도록 만들 수 있다. 

-push, pop, peek를 실행하기 전에 스택이 적절한 상태인지 검사하기 위한 isEmpty함수와 isFull함수를 작성하였다. 

-enqueue() : 매개변수로 받은 Print타입의 요소를 후단에 넣어주었다. 만약에 rear의 값이 배열의 사이즈를 넘기면 나머지 연산을 사용하여 인덱스를 원형으로 회전시킨다. 

-pop() : 맨 앞에 있는 요소를 리턴하고, front값을 +1을 해주어 값을 삭제해줄 수 있다. 

-peek() : 맨 위에 있는 값을 보여주는 함수

-display() : 원형 큐의 시작지점인 front에서 rear까지 출력해야 하는데 front가 rear보다 index값이 작은 형태로 있으면 rear에 배열사이즈 만큼 더하여서 배열을 돌아야한다. 요소를 출력할때는 index를 배열사이즈만큼 나눈 나머지를 이용하여 출력한다. 

-getSize() : movePrintsToOutputQueue()함수를 쓸 때에 두번째 반복문의 반복횟수를 설정해주기 위해 rear-front를 반환하는 함수이다.  getTop함수와 같은 이유로 만들어주었다. 

 

class PrinterSim{ } 

class PrinterSim {
private:
    InputPrintStack input;
    OutputPrintQueue output;

public:
    void insertInputPrints(Print x) { input.push(x); }

    void removePrintJob() { input.pop(); }

    int compareImportance(Print a, Print b) {
        if (a.getImp() > b.getImp()) return 0;
        else if (a.getImp() < b.getImp()) return -1;
        else return 1;
    }

    int comparePages(Print a, Print b) {
        if (a.getPages() > b.getPages()) return 1;
        else if (a.getPages() < b.getPages()) return -1;
    }

    //outputPrintsByImportance()에서 중복되는 코드를 함수로 만듦
    void swap(Print& a, Print& b) {
        Print temp = a;
        a = b;
        b = temp;
    }

    void movePrintsToOutputQueue() {
        int roop = input.getTop();
        for (int i = 0; i < roop + 1; i++) output.enqueue(input.pop());
    }

    void outputPrintsByImportance() {
        cout << "Result: ";
        int roop = output.getTop() - 1;
        for (int j = 0; j < roop; j++) { // roop1 11번 반복
            Print MaxImp = output.dequeue();
            for (int i = 0; i < roop - j; i++) { //roop1를 한번 돌때마다 roop2의 반복횟수가 줄어듬
                Print temp = output.dequeue();

                int resultImp = compareImportance(MaxImp, temp);
                if (resultImp == -1) { swap(MaxImp, temp); } //temp의 Imp값이 MaxImp의 Imp보다 클때 swap함수를 사용하여 자리를 바꿈
                else if (resultImp == 1) {
                    int resultPages = comparePages(MaxImp, temp);
                    if (resultPages == -1) { swap(MaxImp, temp); } //temp의 Pages값이 MaxImp의 Pages보다 클때 swap함수를 사용하여 자리를 바꿈
                    else;
                }
                else;
                //MaxImp와 tmep 둘중에 중요도가 낮은것은 다시 output큐로 넣음
                output.enqueue(temp);
            }
            cout << MaxImp.getUser() << " ";
        }
        //마지막 하나 남은 큐 cout하기
        cout << output.dequeue().getUser();
    }

    void displayInput() { input.display(); }

    void displayOutput() { output.display(); }
};

-InputPrintStack형의 input객체, OutputPrintQueue형의 output객체

-insertInputPrints(Print x) : 인수로 받은 Print형의 x를 input에 삽입한다. 
-removePrintJob() : 직전에 들어온 인쇄 요청을 삭제한다.즉input에 들어온 Print 요소를 삭제한다.

-compareImportance(Print a, Print b) : 중요도 비교 
-comparePages(Print a, Print b) : 페이지 수 비교 

-swap() : outputPrintsByImportance()에서 MaxImp와 temp의 값을 서로 바꾸는 함수. 매개변수를 참조자를 사용하여 call by reference로 받아야 함수의 호출이 종료되고 나서도 값이 유효하다. (call by value를 사용하면 복사생성자가 호출되어서  outputPrintsByImportance함수의 변수와는 별개의 요소가 됨)

-movePrintsToOutputQueue() : InputPrintStack클래스에서 정의해준 getTop함수로 스택의 크기를 받아와서 반복문의 횟수를 변수roop에 저장해주고 사용한다. 
output.enqueue(input.pop()) : input객체의 배열에서 pop한 요소를 매개변수로 사용하여 output의 큐에 넣어준다. 

-outputPrintsByImportance() :  
 (1) 첫번째 for문의 반복횟수를 스택의 크기-1만큼 정해줌. (반복문이 끝날때 마다 큐의 제일 높은 중요도를 가진 Print형의 요소를 출력하는 것을 스택사이즈-1만큼 반복한다)
 (2) 두번째 반복문을 돌기전에 output 큐의 맨앞의 값을 dequeue해서 MaxImp에 저장함.
 (3) 반복문 안에서 output 큐를 dequeue해서 temp에 저장함
 (4) MaxImp와 temp를 비교. 만약 Imp값이 MaxImp가 더 크면 그대로 있고, temp가 더 크면 위에서 정의한 swap함수를 사용하여 MaxImp에 temp를 저장하여 다음 dequeue되는 값과 비교. temp값은 다시 output에 enqueue함
 (5) 두번째 반복문의 횟수를 "i < roop - j"로 정해주어 하나 씩 삭제되는 큐의 길이를 반영하여 반복한다. 
 (6)마지막루프를 돌 때까지의 MaxImp의 요소가 imp값이 제일 큰 요소가 된다. -> 삭제, 출력
 (7)큐의 값이 하나만 남았을 때 반복문을 종료하고 그 값을 삭제, 출력함

-displayInput() : input스택의 요소들을 모두 출력
-displayOutput() : output큐의 요소들을 모두 출력

                        

  • 전체 코드
더보기
#define _CRT_SECURE_NO_WARNINGS 
#include <iostream>
#include <string>
using namespace std;

const int MAX_INPUT_SIZE = 15;

inline void error(const char* message) {
    printf("%s\n", message);
    exit(1);
}

class Print {
private:
    char user[10];
    int imp; // 중요도는 1 to 5 까지만 가능
    int pages; //페이지수는 1 to 20 까지만 가능

public:
    Print() { } // 기본 생성자
    Print(const char* u, int i, int p) { // 매개 변수가 있는 생성자
        strcpy(user, u);
        imp = i;
        pages = p;
    }
    ~Print() {} // 소멸자

    char* getUser() { // user를 반환
        return user;
    }

    int getImp() { // imp(중요도)를 반환
        return imp;
    }

    int getPages() { // pages(페이지 수)를 반환
        return pages;
    }

    void setImp(int i) { // imp(중요도)를 설정
        imp = i;
    }

    void setPages(int p) { // pages(페이지 수)를 설정
        pages = p;
    }
};

class InputPrintStack {
private:
    int top;
    Print data[MAX_INPUT_SIZE];
public:
    InputPrintStack() { top = -1; }
    ~InputPrintStack() {}
    bool isEmpty() { return top == -1; }
    bool isFull() { return top == MAX_INPUT_SIZE - 1; }

    void push(Print x) {
        if (isFull()) error("스택 포화 에러");
        data[++top] = x;
    }

    Print pop() {
        if (isEmpty()) error("스택 공백 에러");
        return data[top--];
    }

    Print peek() {
        if (isEmpty()) error("스택 공백 에러");
        return data[top];
    }

    void display() {
        cout << " Stack: ";
        for (int i = 0; i <= top; i++) cout << data[i].getUser() << " ";
        cout << endl;
    }
    //movePrintsToOutputQueue()함수를 쓸 때에 반복문의 반복횟수를 설정해주기 위해 top(=size-1)을 반환하는 함수이다. 
    //top은 int로 다른 클래스에서 접근하지 못하기 때문에 getTop()함수를 만들어 값을 참조(not &reference)할 수 있게하였다. 
    int getTop() { return top; }
};

class OutputPrintQueue {
public:
    int front;
    int rear;
    Print data[MAX_INPUT_SIZE];
public:
    OutputPrintQueue() { front = rear = 0; }
    ~OutputPrintQueue() {}
    bool isEmpty() { return front == rear; }
    bool isFull() { return (rear + 1) % MAX_INPUT_SIZE == front; }

    void enqueue(Print x) {
        if (isFull()) error(" error: 큐가 포화상태입니다.\n");
        else {
            rear = (rear + 1) % MAX_INPUT_SIZE;
            data[rear] = x;
        }
    }

    Print dequeue() {
        if (isEmpty()) error(" error: 큐가 공백상태입니다.\n");
        else {
            front = (front + 1) % MAX_INPUT_SIZE;
            return data[front];
        }
    }

    Print peek() {
        if (isEmpty()) error(" error: 큐가 공백상태입니다.\n");
        else {
            return data[(front + 1) % MAX_INPUT_SIZE];
        }
    }

    void display() {
        cout << " Queue: ";
        int maxi = (front < rear) ? rear : rear + MAX_INPUT_SIZE;
        for (int i = front + 1; i <= maxi; i++) cout << data[i % MAX_INPUT_SIZE].getUser() << " ";
        cout << endl;
    }
    //outputPrintsByImportance()에서 반복문횟수를 정하기 위한 size값을 함수로 넘겨줌
    int getSize() {
        int maxi = (front < rear) ? rear : rear + MAX_INPUT_SIZE;
        return maxi-front;
    }

};

class PrinterSim {
private:
    InputPrintStack input;
    OutputPrintQueue output;

public:
    void insertInputPrints(Print x) { input.push(x); }

    void removePrintJob() { input.pop(); }

    int compareImportance(Print a, Print b) {
        if (a.getImp() > b.getImp()) return 0;
        else if (a.getImp() < b.getImp()) return -1;
        else return 1;
    }

    int comparePages(Print a, Print b) {
        if (a.getPages() > b.getPages()) return 1;
        else if (a.getPages() < b.getPages()) return -1;
    }

    //outputPrintsByImportance()에서 중복되는 코드를 함수로 만듦
    void swap(Print& a, Print& b) {
        Print temp = a;
        a = b;
        b = temp;
    }

    void movePrintsToOutputQueue() {
        int roop = input.getTop();
        for (int i = 0; i < roop + 1; i++) output.enqueue(input.pop());
    }

    void outputPrintsByImportance() {
        cout << "Result: ";
        int roop1 = output.getSize() - 1, roop2 = output.getSize() - 1; // roop=11
        for (int j = 0; j < roop1; j++) { // roop1 11번 반복
            Print MaxImp = output.dequeue();
            for (int i = 0; i < roop2 - j; i++) { //roop1를 한번 돌때마다 roop2의 반복횟수가 줄어듬
                Print temp = output.dequeue();

                int resultImp = compareImportance(MaxImp, temp);
                if (resultImp == -1) { swap(MaxImp, temp); } //temp의 Imp값이 MaxImp의 Imp보다 클때 swap함수를 사용하여 자리를 바꿈
                else if (resultImp == 1) {
                    int resultPages = comparePages(MaxImp, temp);
                    if (resultPages == -1) { swap(MaxImp, temp); } //temp의 Pages값이 MaxImp의 Pages보다 클때 swap함수를 사용하여 자리를 바꿈
                    else;
                }
                else;
                //MaxImp와 tmep 둘중에 중요도가 낮은것은 다시 output큐로 넣음
                output.enqueue(temp);
            }
            cout << MaxImp.getUser() << " ";
        }
        //마지막 하나 남은 큐 cout하기
        cout << output.dequeue().getUser();
    }

    void displayInput() { input.display(); }

    void displayOutput() { output.display(); }
};


int main() {
    PrinterSim sim;

    sim.insertInputPrints(Print("A", 1, 5));
    sim.insertInputPrints(Print("B", 2, 13));
    sim.insertInputPrints(Print("C", 3, 3));
    sim.insertInputPrints(Print("D", 4, 15));
    sim.insertInputPrints(Print("E", 5, 10));
    sim.removePrintJob();
    sim.insertInputPrints(Print("F", 2, 10));
    sim.removePrintJob();
    sim.insertInputPrints(Print("G", 3, 10));
    sim.removePrintJob();
    sim.insertInputPrints(Print("H", 4, 20));
    sim.insertInputPrints(Print("I", 5, 20));
    sim.insertInputPrints(Print("J", 4, 18));
    sim.insertInputPrints(Print("K", 1, 20));
    sim.removePrintJob();
    sim.insertInputPrints(Print("L", 4, 10));
    sim.insertInputPrints(Print("M", 5, 19));
    sim.insertInputPrints(Print("N", 2, 19));
    sim.removePrintJob();
    sim.insertInputPrints(Print("O", 1, 19));
    sim.insertInputPrints(Print("P", 1, 18));
    sim.removePrintJob();
    sim.insertInputPrints(Print("Q", 3, 18));
    sim.insertInputPrints(Print("R", 4, 19));
    //인쇄 요청 끝

    sim.displayInput();
    sim.movePrintsToOutputQueue();
    sim.displayOutput();
    sim.outputPrintsByImportance();
    //인쇄 요청 처리 끝

    return 0;

}

 

 

과제를 제출하고 오류를 찾음

과제를 제출하고 나서 생각하니 어차피 인쇄요청이 끝나고 stack을 queue에 복사하는 것이니  outputPrintsByImportance()함수에서 roop변수를 1과 2로 나눌 필요도 없었고, getSize함수를 만들 필요도 없었다. .... 심지어 제출한 코드에서getSize함수에  maxi-front를 리턴해야하는데 maxi만 리턴함 ㅜ

 

고친코드

void outputPrintsByImportance() {
        cout << "Result: ";
        int roop = input.getTop() - 1;
        for (int j = 0; j < roop; j++) { // roop1 11번 반복
            Print MaxImp = output.dequeue();
            for (int i = 0; i < roop - j; i++) { //roop1를 한번 돌때마다 roop2의 반복횟수가 줄어듬
                Print temp = output.dequeue();

                int resultImp = compareImportance(MaxImp, temp);
                if (resultImp == -1) { swap(MaxImp, temp); } //temp의 Imp값이 MaxImp의 Imp보다 클때 swap함수를 사용하여 자리를 바꿈
                else if (resultImp == 1) {
                    int resultPages = comparePages(MaxImp, temp);
                    if (resultPages == -1) { swap(MaxImp, temp); } //temp의 Pages값이 MaxImp의 Pages보다 클때 swap함수를 사용하여 자리를 바꿈
                    else;
                }
                else;
                //MaxImp와 tmep 둘중에 중요도가 낮은것은 다시 output큐로 넣음
                output.enqueue(temp);
            }
            cout << MaxImp.getUser() << " ";
        }
        //마지막 하나 남은 큐 cout하기
        cout << output.dequeue().getUser();
    }

 

 

 

배운점, 느낀점

과제를 하면서 클래스의 구조를 더 유기적으로 생각하면서 코딩할 수 있었다.