Add destructors to the C++ codes.

This commit is contained in:
Yudong Jin
2023-01-14 19:52:11 +08:00
parent 87acfc91ab
commit bb657f9517
19 changed files with 121 additions and 24 deletions

View File

@ -21,6 +21,10 @@ public:
nums = new int[capacity];
}
~ArrayQueue() {
delete[] nums;
}
/* 获取队列的容量 */
int capacity() {
return cap;
@ -117,5 +121,8 @@ int main() {
PrintUtil::printVector(queue->toVector());
}
// 释放内存
delete queue;
return 0;
}

View File

@ -78,5 +78,8 @@ int main() {
bool empty = stack->empty();
cout << "栈是否为空 = " << empty << endl;
// 释放内存
delete stack;
return 0;
}

View File

@ -19,6 +19,11 @@ public:
queSize = 0;
}
~LinkedListQueue() {
delete front;
delete rear;
}
/* 获取队列的长度 */
int size() {
return queSize;
@ -108,5 +113,8 @@ int main() {
bool empty = queue->empty();
cout << "队列是否为空 = " << empty << endl;
// 释放内存
delete queue;
return 0;
}

View File

@ -18,6 +18,10 @@ public:
stkSize = 0;
}
~LinkedListStack() {
freeMemoryLinkedList(stackTop);
}
/* 获取栈的长度 */
int size() {
return stkSize;
@ -97,5 +101,8 @@ int main() {
bool empty = stack->empty();
cout << "栈是否为空 = " << empty << endl;
// 释放内存
delete stack;
return 0;
}