the space coding
◈스 택 Q
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111 |
#include<iostream>
using namespace std;
class Memory {
protected:
int*p;
public:
int i;
Memory() {
p = new int[20];
i = 0;
}
~Memory() { delete[]p; }
void push() {
if (i>19) {
cout << "더 이상 입력 할 수 없습니다." << endl;
}
else if (i<19) {
cout << "입력을 하시오" << endl;
cin >> p[i];
i++;
}
}
virtual void pop() = 0;
void printAll() {
for (int j = 0; j < i; j++)
{
cout << p[j] << endl;
}
}
};
class MyStack : public Memory {
public:
void pop() {
if (i == 0) {
cout << "더 이상 값이 없습니다." << endl;
}
else {
i--;
p[i] = NULL;
}
}
};
class MyQueue : public Memory {
public:
void pop() {
if (i == 0) {
cout << "더 이상 값이 없습니다." << endl;
}
else {
for (int j = 0; j < i; j++)
{
p[j] = p[j + 1];
p[i] = NULL;//0
}i--;
}
}
};
void main() {
Memory*p;
MyStack ms;
MyQueue mq;
int num, num2, num3;
cout << "1.스텍 2.큐 : ";
cin >> num;
switch (num) {
p = &ms;
while (true) {
cout << "1.push 2.pop 3.출력:";
cin >> num2;
switch (num2) {
case 1:
p->push();
break;
case 2:
p->pop();
break;
case 3:
p->printAll();
break;
}
}
break;
case 2:
p = &mq;
while (true) {
cout << "1.push 2.pop 3.출력:";
cin >> num3;
switch (num3) {
case 1:
p->push();
break;
case 2:
p->pop();
break;
case 3:
p->printAll();
}
}
break;
}
} |
cs |
'C++' 카테고리의 다른 글
[C++]깊은 대입연산자함수 (0) | 2018.03.21 |
---|---|
[C++] operator 함수 (0) | 2018.03.21 |
◈ 오버로딩이 불가능한 연산자의 종류 (0) | 2018.03.21 |
[c++] public / protected / private (0) | 2018.03.21 |
[java][성적 관리프로그램] (0) | 2018.03.21 |