Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <windows.h>
- using namespace std;
- struct elem
- {
- int key; elem *next;
- }*stack = NULL;
- void push(int n)
- {
- elem *p = stack;
- stack = new elem;
- stack->key = n;
- stack->next = p;
- }
- int pop(int &n)
- {
- if (stack)
- {
- n = stack->key;
- elem *p = stack;
- stack = stack->next;
- delete p;
- return 1;
- }
- else return 0;
- }
- void main()
- {
- int N = 5;
- int n;
- int array[4];
- int size,value;
- SetConsoleCP(1251);SetConsoleOutputCP(1251);
- cout<<"Въведете размер:\n";
- cin >> size;
- for (int i = 0; i < size; i++)
- {
- cout<<"Въведете число:\n";
- cin >> value;
- push(value);
- }
- for (int i = 0; i < N-1; i++)
- {
- pop(array[i]);
- }
- pop(n);
- for (int i = N-1; i > 0; i--)
- {
- push(array[i-1]);
- }
- cout << "\nСтек: ";
- while (pop(N))
- {
- cout << N << " ";
- }
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement