Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class tipog>
- class NodeDay
- {
- public:
- NodeDay(tipog year, tipog month, tipog day){
- this->year = year;
- this->month = month;
- this->day = day;
- }
- tipog year;
- tipog mont;
- tipog day;
- nDia<tipog>* next = nullptr;
- nDia<tipog>* prev = nullptr;
- EList<tipog>* events = new ListaE<tipog>();
- };
- template<class tipog, class tipoh>
- class nodeEvent
- {
- public:
- tipog title, desc, duration;
- tipoh iniHr;
- nodeEvent<tipog, tipoh>* next = nullptr;
- nodeEvent(tipog tit, tipog desc, tipoh hr, tipog dur){
- this->title = tit;
- this->desc = desc;
- this->iniHr = hr;
- this->duration = dur;
- }
- };
- template<class tipog>
- class listD
- {
- public:
- NodeDay<tipog>* first = nullptr;
- NodeDay<tipog>* pList = nullptr;
- NodeDay<tipog>* last = nullptr;
- listD(){
- }
- void addDay(tipog anio, tipog mes, tipog dia, nEvento<tipog,tipog>* even);
- bool emptyList() { return first == nullptr; }
- bool greaterThan(nDia<tipog>* aux, nDia<tipog>* nuevo);
- bool smallerThan(nDia<tipog>* aux, nDia<tipog>* nuevo);
- bool equals(nDia<tipog> *aux, nDia<tipog> *nuevo, nEvento<tipog, tipog> *event);
- void goToFirst();
- void next();
- void goToLast();
- };
- template<class tipog>
- void listD<tipog>::addDay(tipog a, tipog m, tipog d, nEvento<tipog,tipog>* even){
- NodeDay<tipog>* newDay = new NodeDay<tipog>(a, m, d);
- newDay->events->newEvent(even);
- goToFirst();
- if(emptyList() || greaterThan(first, newDay)){
- if(!first){
- first = newDay;
- pList = newDay;
- last = newDay;
- first->prev = last;
- last->next = first;
- }
- else{
- newDay->next = first;
- first->prev = newDay;
- newDay->prev = last;
- last->next = newDay;
- first = new;
- }
- }else{
- while(pList->next != first && smallerThan(pList->next, newDay)){
- next();
- smallerThan returns true if the active node is smaller than newDay, if it is, the active node goes to the next node.
- }
- if(equals(pList,newDay,even)){
- //The equals methor checks if the newDay is the same as the active node, if it is, it adds the event to that day
- }else{
- newDay->next = pList->next;
- newDay->prev = pList;
- pList->next = newDay;
- if(newDay->next == first){
- first->prev = newDay;
- last = newDay;
- }else{
- newDay->next->prev = newDay;
- }
- }
- }
- }
- template<class tipog>
- class EList
- {
- public:
- EList(){
- }
- nodeEvent<tipog, tipog>* firstE = nullptr;
- nodeEvent<tipog, tipog>* pEvent = nullptr;
- void newEvent(nEvento<tipog,tipog>* even);
- bool emptyList() { return primerE == nullptr; }
- void first();
- };
- template<class tipog>
- void EList<tipog>::newEvent(nodeEvent<tipog,tipog>* even){
- nodeEvent<tipog,tipog>* newE = even;
- if(emptyList() || firstE->IniHr > even->IniHr){
- if(!firstE){
- firstE = newE;
- }else{
- newE->next = firstE;
- firstE = newE;
- }
- }else{
- nodeEvent<tipog,tipog>* active = firstE;
- while(active->next != nullptr && active->next->iniHr <= even->iniHr){
- if(active) active = active->next;
- }
- newE->next = active->next;
- active->next = newE;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement