Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. template<class tipog>
  2. class NodeDay
  3. {
  4. public:
  5. NodeDay(tipog year, tipog month, tipog day){
  6.  
  7. this->year = year;
  8. this->month = month;
  9. this->day = day;
  10. }
  11.  
  12. tipog year;
  13. tipog mont;
  14. tipog day;
  15.  
  16. nDia<tipog>* next = nullptr;
  17. nDia<tipog>* prev = nullptr;
  18.  
  19.  
  20. EList<tipog>* events = new ListaE<tipog>();
  21.  
  22. };
  23.  
  24. template<class tipog, class tipoh>
  25. class nodeEvent
  26. {
  27. public:
  28. tipog title, desc, duration;
  29. tipoh iniHr;
  30.  
  31. nodeEvent<tipog, tipoh>* next = nullptr;
  32.  
  33. nodeEvent(tipog tit, tipog desc, tipoh hr, tipog dur){
  34. this->title = tit;
  35. this->desc = desc;
  36. this->iniHr = hr;
  37. this->duration = dur;
  38. }
  39. };
  40.  
  41. template<class tipog>
  42. class listD
  43. {
  44. public:
  45.  
  46. NodeDay<tipog>* first = nullptr;
  47. NodeDay<tipog>* pList = nullptr;
  48. NodeDay<tipog>* last = nullptr;
  49.  
  50. listD(){
  51.  
  52. }
  53.  
  54. void addDay(tipog anio, tipog mes, tipog dia, nEvento<tipog,tipog>* even);
  55. bool emptyList() { return first == nullptr; }
  56. bool greaterThan(nDia<tipog>* aux, nDia<tipog>* nuevo);
  57. bool smallerThan(nDia<tipog>* aux, nDia<tipog>* nuevo);
  58. bool equals(nDia<tipog> *aux, nDia<tipog> *nuevo, nEvento<tipog, tipog> *event);
  59. void goToFirst();
  60. void next();
  61. void goToLast();
  62. };
  63.  
  64. template<class tipog>
  65. void listD<tipog>::addDay(tipog a, tipog m, tipog d, nEvento<tipog,tipog>* even){
  66.  
  67. NodeDay<tipog>* newDay = new NodeDay<tipog>(a, m, d);
  68. newDay->events->newEvent(even);
  69.  
  70. goToFirst();
  71.  
  72. if(emptyList() || greaterThan(first, newDay)){
  73.  
  74. if(!first){
  75. first = newDay;
  76. pList = newDay;
  77. last = newDay;
  78.  
  79. first->prev = last;
  80. last->next = first;
  81. }
  82. else{
  83. newDay->next = first;
  84. first->prev = newDay;
  85.  
  86. newDay->prev = last;
  87. last->next = newDay;
  88.  
  89. first = new;
  90. }
  91.  
  92. }else{
  93.  
  94. while(pList->next != first && smallerThan(pList->next, newDay)){
  95. next();
  96. smallerThan returns true if the active node is smaller than newDay, if it is, the active node goes to the next node.
  97. }
  98.  
  99. if(equals(pList,newDay,even)){
  100. //The equals methor checks if the newDay is the same as the active node, if it is, it adds the event to that day
  101. }else{
  102.  
  103. newDay->next = pList->next;
  104. newDay->prev = pList;
  105. pList->next = newDay;
  106. if(newDay->next == first){
  107. first->prev = newDay;
  108. last = newDay;
  109. }else{
  110. newDay->next->prev = newDay;
  111. }
  112.  
  113. }
  114.  
  115. }
  116. }
  117.  
  118. template<class tipog>
  119. class EList
  120. {
  121. public:
  122. EList(){
  123.  
  124. }
  125.  
  126. nodeEvent<tipog, tipog>* firstE = nullptr;
  127. nodeEvent<tipog, tipog>* pEvent = nullptr;
  128.  
  129. void newEvent(nEvento<tipog,tipog>* even);
  130. bool emptyList() { return primerE == nullptr; }
  131. void first();
  132. };
  133.  
  134. template<class tipog>
  135. void EList<tipog>::newEvent(nodeEvent<tipog,tipog>* even){
  136.  
  137. nodeEvent<tipog,tipog>* newE = even;
  138.  
  139. if(emptyList() || firstE->IniHr > even->IniHr){
  140. if(!firstE){
  141. firstE = newE;
  142. }else{
  143. newE->next = firstE;
  144. firstE = newE;
  145. }
  146. }else{
  147.  
  148. nodeEvent<tipog,tipog>* active = firstE;
  149. while(active->next != nullptr && active->next->iniHr <= even->iniHr){
  150. if(active) active = active->next;
  151. }
  152. newE->next = active->next;
  153. active->next = newE;
  154. }
  155. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement