Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "Cvor.h"
- struct RedSekv {
- private:
- int vel = 4;
- Tip* N = new Tip[vel];
- int brojac = 0;
- int kraj = 0;
- int pocetak = 0;
- void ProsiriNiz()
- {
- Tip * novi = new Tip[vel * 2];
- int j = pocetak;
- for (size_t i = 0; i < brojac; i++)
- {
- novi[i] = N[j];
- j++;
- if (j == vel)
- j = 0;
- }
- delete[]N;
- N = novi;
- pocetak = 0;
- kraj = brojac;
- vel =vel* 2;
- }
- public:
- bool JeLiPuna()
- {
- return brojac == vel;
- }
- void Dodaj(Tip x)
- {
- if (JeLiPuna())
- {
- /*cout << "Red je pun!" << endl;
- return;*/
- ProsiriNiz();
- }
- N[kraj] = x;
- kraj++;
- brojac++;
- if (kraj == vel)
- kraj = 0;
- };
- void Print()
- {
- int i = pocetak;
- for (size_t j = 0; j < brojac; j++)
- {
- cout << N[i]<<" ";
- i++;
- if (i == vel)
- i = 0;
- }
- cout << endl;
- cout << pocetak << " : " << kraj << endl;
- };
- int getBrojac()
- {
- return brojac;
- }
- Tip Ukloni()
- {
- if (JeLiPrazna())
- {
- cout << "Red je prazan!" << endl;
- return 0;
- }
- Tip x = N[pocetak];
- pocetak++;
- if (pocetak == vel)
- pocetak = 0;
- brojac--;
- return x;
- }
- bool JeLiPrazna()
- {
- return brojac == 0;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement