Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int maxn = 1000;
- struct stek {
- int niza[maxn];
- int idx;
- void init() {
- idx = -1;
- }
- void push(int x) {
- if(idx + 1 >= maxn) {
- cout << "NEMA DOVOLNO KAPACITET" << endl;
- return;
- }
- idx++;
- niza[idx] = x;
- }
- int pop() {
- if(idx == -1) {
- cout << "NEMA NITU EDEN ELEMENT VO STEKOT" << endl;
- return -1;
- }
- int result = niza[idx];
- idx--;
- return result;
- }
- int top() {
- if(idx == -1) {
- cout << "NEMA NITU EDEN ELEMENT VO STEKOT" << endl;
- return -1;
- }
- return niza[idx];
- }
- int size() {
- return idx + 1;
- }
- int isEmpty() {
- if(idx == -1) {
- return 1;
- }
- else {
- return 0;
- }
- }
- };
- int main() {
- int broj;
- cin >> broj;
- stek s;
- s.init();
- while(broj > 0) {
- int cifra = broj % 10;
- broj /= 10;
- s.push(cifra);
- }
- while(s.isEmpty() == 0) {
- cout << s.pop() << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement