Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- #define N 100
- class Stack
- {
- protected:
- int *Value;
- int size, top;
- public: Stack();
- ~Stack();
- virtual void pop()
- {
- if (Value[top - 1]){
- Value[top - 1] = NULL;
- top--;
- }
- else cout << endl << "Стек пуст!";
- }
- void push(int x)
- {
- if (top < size)
- {
- Value[top] = x;
- top++;
- }
- else cout << "Ошибка! Стек заполнен! "<<endl;
- }
- bool empty()
- {
- if (top == 0)
- return true;
- else
- return false;
- }
- bool full()
- {
- if (top == size - 1)
- return true;
- else
- return false;
- }
- void show()
- {
- int k = 0;
- while (Value[k]){
- cout << Value[k]<< endl;
- k++;
- }
- }
- };
- Stack::Stack()
- {
- Value = new int[N];
- size = N;
- top = 0;
- for (int i = 0; i < N; i++)
- {
- Value[i] = NULL;
- }
- };
- Stack::~Stack(){
- }
- class Queue :public Stack
- {
- public:
- Queue();
- ~Queue();
- void pop()
- {
- Value[0] = NULL;
- int temp = Value[0];
- for (int i = 1; i < size; i++)
- {
- Value[i - 1] = Value[i];
- }
- Value[size - 1] = temp;
- }
- };
- Queue::Queue()
- {
- Value = new int[N];
- size = N;
- top = 0;
- for (int i = 0; i < N; i++)
- {
- Value[i] = NULL;
- }
- };
- Queue::~Queue(){
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale(LC_ALL, "Russian");
- Stack stack;
- int M;
- cout << "Введите количество элементов стека: " << endl;
- cin >> M;
- cout << "Введите элементы стека: " << endl;
- for (int i = 0; i < M; i++)
- {
- int x;
- cin >> x;
- stack.push(x);
- }
- cout << "Полученный стек: " << endl;
- stack.show();
- cout << "Стек с удаленным элементом: " << endl;
- stack.pop();
- stack.show();
- Queue queue;
- int L;
- cout << "Введите количество элементов очереди: " << endl;
- cin >> L;
- cout << "Введите элементы очереди: " << endl;
- for (int i = 0; i < L; i++)
- {
- int x;
- cin >> x;
- queue.push(x);
- }
- cout << "Полученная очередь: " << endl;
- queue.show();
- queue.pop();
- cout << "Очередь с удаленным элементом: " << endl;
- queue.show();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement