Advertisement
Grossos

synthesis and analysis of algorithms and logics

Mar 12th, 2017
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include<iostream>
  2. #include <windows.h>
  3. using namespace std;
  4. struct elem
  5. {
  6.     int key; elem *next;
  7. }*stack = NULL;
  8.  
  9. void push(int n)
  10. {
  11.     elem *p = stack;
  12.     stack = new elem;
  13.     stack->key = n;
  14.     stack->next = p;
  15. }
  16. int pop(int &n)
  17. {
  18.     if (stack)
  19.     {
  20.         n = stack->key;
  21.         elem *p = stack;
  22.         stack = stack->next;
  23.         delete p;
  24.         return 1;
  25.     }
  26.     else     return 0;
  27. }
  28. void main()
  29.  
  30. {    
  31.         int N = 5;
  32.         int n;
  33.     int array[4];
  34.     int size,value;
  35.  
  36.    
  37.         SetConsoleCP(1251);SetConsoleOutputCP(1251);
  38.                             cout<<"Въведете размер:\n";
  39.                             cin >> size;
  40.  
  41.     for (int i = 0; i < size; i++)
  42.     {
  43.         cout<<"Въведете число:\n";
  44.         cin >> value;
  45.         push(value);
  46.        
  47.     }
  48.  
  49.     for (int i = 0; i < N-1; i++)
  50.     {
  51.         pop(array[i]);
  52.     }
  53.  
  54.     pop(n);
  55.  
  56.     for (int i = N-1; i > 0; i--)
  57.     {
  58.  
  59.         push(array[i-1]);
  60.     }
  61.     cout << "\nСтек:  ";
  62.  
  63.     while (pop(N))
  64.     {
  65.         cout << N << "  ";
  66.     }  
  67.     system("PAUSE");
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement