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 red {
- int niza[max_size];
- int front, rear;
- void init() {
- front = 0;
- rear = -1;
- }
- bool isEmpty() {
- if(rear == -1) {
- return true;
- }
- else {
- return false;
- }
- }
- bool isFull() {
- if(rear == max_size - 1) {
- return true;
- }
- else {
- return false;
- }
- }
- void push(int element) {
- if(isFull()) {
- cout << "Redot e poln" << endl;
- return;
- }
- rear++;
- niza[rear] = element;
- }
- void pop() {
- if(isEmpty()) {
- cout << "Nema elementi vo redot" << endl;
- return;
- }
- for(int i = front; i < rear; i++) {
- niza[i] = niza[i + 1];
- }
- rear--;
- }
- int peek() {
- if(isEmpty()) {
- cout << "Prazen red" << endl;
- return -1;
- }
- return niza[front];
- }
- };
- int main()
- {
- red q;
- q.init();
- q.push(10);
- q.push(5);
- q.push(3);
- cout << q.peek() << endl;
- q.pop();
- cout << q.peek() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement