Advertisement
Josif_tepe

Untitled

Feb 26th, 2025
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int maxn = 1000;
  5.  
  6. struct stek {
  7.     int niza[maxn];
  8.     int idx;
  9.    
  10.     void init() {
  11.         idx = -1;
  12.     }
  13.    
  14.     void push(int x) {
  15.         if(idx + 1 >= maxn) {
  16.             cout << "NEMA DOVOLNO KAPACITET" << endl;
  17.             return;
  18.         }
  19.         idx++;
  20.         niza[idx] = x;
  21.     }
  22.    
  23.     int pop() {
  24.         if(idx == -1) {
  25.             cout << "NEMA NITU EDEN ELEMENT VO STEKOT" << endl;
  26.             return -1;
  27.         }
  28.         int result = niza[idx];
  29.         idx--;
  30.         return result;
  31.     }
  32.    
  33.     int top() {
  34.         if(idx == -1) {
  35.             cout << "NEMA NITU EDEN ELEMENT VO STEKOT" << endl;
  36.             return -1;
  37.         }
  38.         return niza[idx];
  39.     }
  40.    
  41.     int size() {
  42.         return idx + 1;
  43.     }
  44.    
  45.     int isEmpty() {
  46.         if(idx == -1) {
  47.             return 1;
  48.         }
  49.         else {
  50.             return 0;
  51.         }
  52.     }
  53. };
  54. int main() {
  55.     int broj;
  56.     cin >> broj;
  57.    
  58.     stek s;
  59.     s.init();
  60.    
  61.     while(broj > 0) {
  62.         int cifra = broj % 10;
  63.         broj /= 10;
  64.        
  65.         s.push(cifra);
  66.     }
  67.    
  68.     while(s.isEmpty() == 0) {
  69.         cout << s.pop() << endl;
  70.     }
  71.    
  72.     return 0;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement