Добавил:
vvrstcnho
Рад, если кому-то помог
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторные работы С++ (для ИВТ) / Готовые лабы С++ / Лаба4 / Laba 4 (8)
.cpp#include <iostream>
#include <locale>
using namespace std;
class stack {
int* s;
int top;
int size;
public:
stack(int max = 100) {
top = -1;
size = max;
s = new int[max];
}
~stack() {
delete[] s;
}
stack& operator=(const stack& other) {
if (this != &other) {
delete[] s;
size = other.size;
top = other.top;
s = new int[size];
for (int i = 0; i <= top; i++) {
s[i] = other.s[i];
}
}
return *this;
}
void push(int value) {
if (top < size - 1) {
s[++top] = value;
}
}
void print() const {
cout << "Стек: ";
for (int i = 0; i <= top; i++) {
cout << s[i] << " ";
}
cout << " (top=" << top << ")" << endl;
}
};
int main() {
setlocale(LC_ALL, "ru_RU.UTF-8");
stack s1(5);
s1.push(1);
s1.push(2);
s1.push(3);
stack s2(3);
s2 = s1;
cout << "s1: ";
s1.print();
cout << "s2: ";
s2.print();
return 0;
}
Соседние файлы в папке Лаба4
