CCCPaste

Untitled

#include 
using namespace std;
const int max_size = 1000;
struct red {
    int niza[max_size];
    int front, rear;
    
    void init() {
        front = 0;
        rear = -1;
    }
    
    int isEmpty() {
        if(rear == -1) {
            return 1;
        }
        else {
            return 0;
        }
    }
    
    int isFull() {
        if(rear == max_size - 1) {
            return 1;
        }
        else {
            return 0;
        }
    }
    
    void push(int x) {
        if(isFull() == 1) {
            cout << "Redot e poln!" << endl;
            return;
        }
        rear++;
        niza[rear] = x;
    }
    
    int pop() {
        if(isEmpty() == 1) {
            cout << "Redot e prazen" << endl;
            return -1;
        }
        int result = niza[front];
        for(int i = front; i < rear; i++) {
            niza[i] = niza[i + 1];
        }
        rear--;
        return result;
    }
    int peek() {
        if(isEmpty() == 1) {
            cout << "Nema elementi vo redot" << endl;
            return -1;
        }
        return niza[front];
    }
};
int main() {

    red Q;
    Q.init();
    
    Q.push(1);
    Q.push(2);
    Q.push(3);
    Q.push(4);
    Q.push(5);
    
    
    while(Q.isEmpty() == 0) {
        cout << Q.pop() << endl;
    }
    
    
    return 0;
}