Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- /*Tema 6. liste de numere întregi 3 (implementate dinamic)
- Se dau urmatoarele clase:
- - Nod (int info);
- - Nod_simplu (nod * next) :Nod
- - Nod_dublu (nod * ante) :Nod_simplu
- - Nod_prioritate (int prio) :Nod_dublu
- - Coada_prioritati (elemente de tip Nod_Prioritate);
- - Coada_simpla : Coada prioritati (elementele au prioritati egale).
- Clasele derivate trebuie sa contina cel puțin constructori parametrizati (prin
- care sa se evidentieze transmiterea parametrilor către constructorul din clasa
- de baza) si destructorI. Să se exemplifice Heapsort utilizand coada cu
- prioritati și Insertionsort utilizand coada simpla.*/
- class Nod{
- protected:
- int info;
- public:
- Nod()
- {
- info = 0;
- }
- Nod(int f)
- {
- info = f;
- }
- ~Nod();
- };
- class Nod_simplu:protected Nod{
- protected:
- Nod *next ;
- public:
- Nod_simplu()
- {
- info = 0;
- next = NULL;
- }
- Nod_simplu(int val)
- {
- info = val;
- next = NULL;
- }
- ~Nod_simplu();
- friend istream& operator>>(istream &inod_simplu,Nod_simplu &x);
- friend ostream& operator<<(ostream &onod_simplu,Nod_simplu &x);
- };
- istream& operator>>(istream & inod_simplu,Nod_simplu &x)
- {
- inod_simplu >> x.info;
- return inod_simplu;
- }
- ostream& operator<<(ostream &onod_simplu,Nod_simplu &x)
- {
- onod_simplu << x.info;
- return onod_simplu;
- }
- class Nod_dublu:protected Nod_simplu{
- protected:
- Nod * ante;
- public:
- Nod_dublu()
- {
- info = 0;
- ante = NULL;
- next = NULL;
- }
- Nod_dublu(int val)
- {
- info = val;
- ante = NULL;
- next = NULL;
- }
- ~Nod_dublu();
- friend istream& operator>>(istream &inod_dublu,Nod_dublu &x);
- friend ostream& operator<<(ostream &onod_dublu,Nod_dublu &x);
- };
- istream& operator>>(istream & inod_dublu,Nod_dublu &x)
- {
- inod_dublu >> x.info;
- return inod_dublu;
- }
- ostream& operator<<(ostream &onod_dublu,Nod_dublu &x)
- {
- onod_dublu << x.info;
- return onod_dublu;
- }
- class Nod_prioritate: protected Nod_dublu{
- protected:
- int prio;
- public:
- Nod_prioritate()
- {
- prio = 0;
- info = 0;
- ante = NULL;
- next = NULL;
- }
- Nod_prioritate(int prior,int infor)
- {
- prio = prior;
- info = infor;
- ante = NULL;
- next = NULL;
- }
- ~Nod_prioritate();
- friend istream& operator>>(istream &inod_prior,Nod_prioritate &x);
- friend ostream& operator<<(ostream &onod_prior,Nod_prioritate &x);
- };
- istream& operator>>(istream & inod_prior,Nod_prioritate &x)
- {
- inod_prior >> x.info;
- inod_prior >> x.prio;
- return inod_prior;
- }
- ostream& operator<<(ostream &onod_prior,Nod_prioritate &x)
- {
- onod_prior << x.info;
- onod_prior << x.prio;
- return onod_prior;
- }
- class Coada_prioritati: protected Nod_prioritate {
- protected:
- Nod_prioritate * nod_prim;
- Nod_prioritate * nod_final;
- public:
- Coada_prioritati()
- {
- info = 0;
- ante = NULL;
- next = NULL;
- prio = 0;
- nod_prim = NULL;
- nod_final = NULL;
- }
- Coada_prioritati(int infor, int prior)
- {
- info = infor;
- ante = NULL;
- next = NULL;
- prio = prior;
- nod_prim = NULL;
- nod_final = NULL;
- }
- void adaugare_nod(int x,int y)
- {
- Nod_prioritate *r = new Nod_prioritate;
- r->info = x;
- r->prio = y;
- r->next = NULL;
- if (nod_prim == NULL)
- {
- nod_prim = r;
- nod_final = r;
- }
- else
- {
- Nod_prioritate * auxx=nod_prim;
- int ok = 1;
- while(ok == 1)
- {
- if(r->prio > auxx->prio)
- {
- r->next = auxx;
- r->ante = auxx->ante;
- auxx->ante = r;
- if(auxx == nod_prim)
- nod_prim = r;
- ok = 0;
- }
- else
- aux=aux->next;
- }
- }
- }
- ~Coada_prioritati();
- friend istream& operator>>(istream &icoada,Coada_prioritati &x);
- friend ostream& operator<<(ostream &ocoada,Coada_prioritati &x);
- };
- istream& operator>>(istream & icoada,Coada_prioritati &x)
- {
- icoada >> x.info;
- icoada >>x.prio;
- return icoada;
- }
- ostream& operator<<(ostream &ocoada,Coada_prioritati &x)
- {
- ocoada << x.info;
- ocoada << x.prio;
- return ocoada;
- }
- class Coada_simpla : protected Coada prioritati{
- public:
- Coada_simpla()
- {
- info = 0;
- ante = NULL;
- next = NULL;
- prio = 0;
- nod_prim = NULL;
- nod_final = NULL;
- }
- Coada_simpla(int infor, int prior)
- {
- info = infor;
- ante = NULL;
- next = NULL;
- prio = prior;
- nod_prim = NULL;
- nod_final = NULL;
- }
- ~Coada_simpla()
- friend istream& operator>>(istream &icoada2,Coada_simpla &x);
- friend ostream& operator<<(ostream &ocoada2,Coada_simpla &x);
- };
- istream& operator>>(istream & icoada2,Coada_simpla &x)
- {
- icoada2 >> x.info;
- icoada2 >> x.prio;
- return icoada2;
- }
- ostream& operator<<(ostream &ocoada,Coada_prioritati &x)
- {
- ocoada2 << x.info;
- ocoada2 << x.prio;
- return ocoada2;
- }
- int main()
- {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement