Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define max 6
- struct stek {
- int top1, top2;
- int s[max];
- };
- void init(stek* st) {
- st->top1 = -1; st->top2 = max;
- }
- void inSt1(stek* st, int x) {
- if (st->top2 - st->top1 == 1)
- cout << "пепеполнение";
- else
- st->s[++st->top1] = x;
- }
- void inSt2(stek* st, int x) {
- if (st->top2 - st->top1 == 1)
- cout << "пепеполнение";
- else
- st->s[--st->top2] = x;
- }
- int outSt1(stek* st) {
- if (st->top1 == -1) {
- cout << "ты че доставать собрался";
- return 0;
- }
- else {
- return st->s[st->top1--];
- }
- }
- int outSt2(stek* st) {
- if (st->top2 == max) {
- cout << "ты че доставать собрался";
- return 0;
- }
- else {
- return st->s[st->top2++];
- }
- }
- void main() {
- stek* st = new(stek);
- init(st);
- inSt1(st, 5);
- inSt1(st, 6);
- inSt1(st, 7);
- inSt2(st, 10);
- inSt2(st, 11);
- inSt2(st, 12);
- cout << outSt1(st) << endl;
- cout << outSt2(st) << endl;
- cout << outSt1(st) << endl;
- cout << outSt2(st) << endl;
- cout << outSt1(st) << endl;
- cout << outSt2(st) << endl;
- cout << "---------------------" << endl;
- inSt1(st, 1);
- inSt1(st, 2);
- inSt1(st, 3);
- inSt1(st, 4);
- inSt1(st, 5);
- inSt1(st, 6);
- cout << outSt1(st) << endl;
- cout << outSt1(st) << endl;
- cout << outSt1(st) << endl;
- cout << outSt1(st) << endl;
- cout << outSt1(st) << endl;
- cout << outSt1(st) << endl;
- cout << "---------------------" << endl;
- inSt2(st, 10);
- inSt2(st, 11);
- inSt2(st, 12);
- inSt2(st, 13);
- inSt2(st, 14);
- inSt2(st, 15);
- cout << outSt2(st) << endl;
- cout << outSt2(st) << endl;
- cout << outSt2(st) << endl;
- cout << outSt2(st) << endl;
- cout << outSt2(st) << endl;
- cout << outSt2(st) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement