Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include "Cvor.h"
- using namespace std;
- template <class Tip>
- struct ListaPov
- {
- Cvor<Tip> * prviCvor = nullptr;
- void DodajNaKraj(Tip x)
- {
- Cvor<Tip>* t = prviCvor;
- if (t == nullptr)
- {
- prviCvor = new Cvor<Tip>(x, nullptr);
- return;
- }
- while (t->next != nullptr)
- {
- t = t->next;
- }
- t->next = new Cvor<Tip>(x, nullptr);
- }
- void DodajNaPocetak(Tip x)
- {
- Cvor<Tip> *t = new Cvor<Tip>(x, prviCvor);
- prviCvor = t;
- }
- Tip UkloniSaKraja()
- {
- if (JeLiPrazna())
- {
- cout << "Greska" << endl;
- return 0;
- }
- Cvor<Tip> * t = prviCvor;
- Cvor *b = nullptr;
- while (t->next != nullptr)
- {
- b = t;
- t = t->next;
- }
- Tip rezultat = t->info;
- delete t;
- if (b != nullptr)
- b->next = nullptr;
- else
- prviCvor = nullptr;
- return rezultat;
- }
- Tip UkloniSaPocetka()
- {
- if (JeLiPrazna())
- {
- cout << "Greska" << endl;
- return 0;
- }
- Cvor<Tip> *t = prviCvor;
- prviCvor = prviCvor->next;
- Tip x = t->info;
- delete t;
- return x;
- }
- void Print()
- {
- Cvor<Tip> *t = prviCvor;
- while (t != nullptr)
- {
- cout << t->info << endl;
- t = t->next;
- }
- }
- bool JeLiPrazna()
- {
- return prviCvor == nullptr;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement