Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class platnosc
- {
- char* nazwa;
- double kwota;
- int dzien;
- int miesiac;
- int rok;
- public:
- platnosc(char*, double, int, int, int);
- bool operator<(const platnosc& p);
- friend std::ostream& operator <<(std::ostream& os, platnosc& p);
- };
- struct lista_platnosci
- {
- platnosc p;
- lista_platnosci* next;
- lista_platnosci(const platnosc& q) : p(q), next(nullptr) {};
- };
- class stos_platnosci
- {
- int pojemnosc;
- protected:
- lista_platnosci* head;
- public:
- stos_platnosci(int p) : head(nullptr), pojemnosc(p) {};
- stos_platnosci & operator --(int)
- {
- if (!head) throw "pusty stos";
- else
- {
- lista_platnosci* q = head, * r = head->next;
- head = r;
- delete q;
- return *this;
- }
- }
- stos_platnosci put(const platnosc & p_)
- {
- if(!head)
- {
- lista_platnosci* head = new lista_platnosci(p_,nullptr);
- return *this;
- }
- else
- {
- int length = 0;
- lista_platnosci* tmp = head;
- while(tmp)
- {
- length++;
- tmp = tmp->next;
- }
- if (length > pojemnosc)
- {
- lista_platnosci* q = new lista_platnosci(p_);
- q->p = p_;
- q->next = head;
- head = q;
- return *this;
- }
- else return *this;
- }
- }
- void empty()
- {
- while(head)
- {
- lista_platnosci* p = head;
- delete p;
- head = head->next;
- }
- }
- ~stos_platnosci() { empty(); };
- };
- class kolejka_wydatkow : public stos_platnosci
- {
- public:
- kolejka_wydatkow(platnosc & p_, int )
- {
- lista_platnosci* q = new lista_platnosci(p_);
- if((!head) || (head->p < p_))
- {
- q->next = head;
- head = q;
- }
- else
- {
- lista_platnosci* r = head;
- while (r->next && (r->next->p < p_))
- r = r->next;
- q->next = r->next;
- r->next = q;
- }
- }
- friend std::ostream& operator<<(std::ostream& os,kolejka_wydatkow &k)
- {
- lista_platnosci* tmp = k.head;
- while(tmp)
- {
- os << tmp->p;
- os << "->";
- tmp = tmp->next;
- }
- return os;
- }
- kolejka_wydatkow operator =(const kolejka_wydatkow& k_)
- {
- if(&k_ == this)
- {
- return *this;
- }
- empty();
- lista_platnosci* q = k_.head;
- while(q)
- {
- put(q->p);
- q = q->next;
- }
- return *this;
- };
- kolejka_wydatkow operator=(kolejka_wydatkow& k_)
- {
- std::swap(head, k_.head);
- return *this;
- }
- kolejka_wydatkow insert(char * nazwa, double kwota, int dzien, int miesiac, int rok)
- {
- platnosc p_(nazwa, kwota, dzien, miesiac, rok);
- lista_platnosci* q = new lista_platnosci(p_);
- if((!head) || q->p < p_)
- {
- q->next = head;
- head = q;
- }
- else
- {
- lista_platnosci* r = head;
- while((r->next) && r->next->p < p_)
- {
- r = r->next;
- }
- q->next = r->next;
- r->next = q;
- }
- }
- ~kolejka_wydatkow() { empty(); };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement