Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int max_size = 1000;
- struct magacin {
- int idx;
- int niza[max_size];
- void init() {
- idx = -1;
- }
- bool isEmpty() {
- if(idx == -1) {
- return true;
- }
- else {
- return false;
- }
- }
- bool isFull() {
- if(idx == max_size - 1) {
- return true;
- }
- else {
- return false;
- }
- }
- int size() {
- return idx + 1;
- }
- void push(int element) {
- if(isFull()) {
- cout << "Nema poveke mesto za elementi" << endl;
- return;
- }
- idx++;
- niza[idx] = element;
- }
- void pop() {
- if(isEmpty()) {
- cout << "Stekot e prazen" << endl;
- return;
- }
- idx--;
- }
- int top() {
- if(isEmpty()) {
- cout << "Nema elementi vo stekot" << endl;
- return -1;
- }
- return niza[idx];
- }
- };
- int main() {
- magacin st;
- st.init();
- st.push(1);
- st.push(2);
- st.push(3);
- cout << st.top() << endl;
- st.pop();
- cout << st.top() << endl;
- st.pop();
- cout << st.top() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement