Advertisement
Iain_Barkley

Untitled

Nov 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include "list.h"
  4.  
  5. Flowlist::Flowlist(): headM(0)
  6. {
  7. }
  8.  
  9. /*
  10. void Flowlist::Flowlist(const Flowlist& rhs)
  11. {
  12. copy(source);
  13.  
  14. }
  15. */
  16.  
  17. /*
  18. Flowlist::~Flowlist()
  19. {
  20. destroy();
  21. }
  22. */
  23. void Flowlist::insert(Node *input)
  24. {
  25. search = headM;
  26.  
  27. if(headM == 0 || input->flow<= headM->flow)
  28. {
  29. input->next = headM;
  30. headM = input;
  31. }
  32. else
  33. {
  34. Node *before = headM;
  35. Node *after = headM->next;
  36. while (after != 0 && input->flow > after->flow)
  37. {
  38. before = after;
  39. after = after ->next;
  40. }
  41. input->next = after;
  42. before-> next = input;
  43. }
  44. }
  45.  
  46. Node* Flowlist::read_item(int n)
  47. {
  48.  
  49. search = headM;
  50.  
  51. for(int i=0; i < n; i++)
  52. {
  53. search = search->next;
  54. }
  55. return search;
  56. }
  57.  
  58. /*
  59. int Flowlist::get_item()
  60. {
  61. int y , z;
  62. double w;
  63. node *x;
  64. x = read_item(const Flow&, int n);
  65. w = x->ListItem->flow;
  66. z= x->ListItem->year;
  67. return
  68. }
  69. */
  70.  
  71. int Flowlist::get_year(int n)
  72. {
  73. search = headM;
  74.  
  75. for(int i=0; i < n; i++)
  76. {
  77. search = search->next;
  78. }
  79. return search->year;
  80. }
  81.  
  82. double Flowlist::get_flow(int n)
  83. {
  84. search = headM;
  85.  
  86. for(int i=0; i < n; i++)
  87. {
  88. search = search->next;
  89. }
  90. return search->flow;
  91. }
  92. //set functions
  93. /*
  94. void Flowlist::Flowlist::operator=(const Flowlist& rhs)
  95. {
  96.  
  97. if (this!= &rhs)
  98. {
  99. destroy();
  100. copy(rhs);
  101. }
  102. return *this;
  103. }
  104. */
  105.  
  106.  
  107. /*
  108. bool Flowlist::check(int y)
  109. {
  110. search = headM;
  111. while(search !=0)
  112. {
  113. search = search->next;
  114.  
  115. }
  116. }
  117. */
  118. bool Flowlist::year_exists(int y)
  119. {
  120. search = find_year(y);
  121. if(search == NULL)
  122. return false;
  123. return true;
  124. }
  125.  
  126. void Flowlist::remove(int y)
  127. {
  128.  
  129. if ((headM == 0 )||(y < headM->year))
  130. return;
  131.  
  132. Node *doomed_node = 0;
  133.  
  134. if (y == headM->year)
  135. {
  136. doomed_node = headM;
  137. headM = headM->next;
  138. }
  139. else
  140. {
  141. Node *before = headM;
  142. Node *maybe_doomed = headM->next;
  143. while(maybe_doomed != 0 && y > maybe_doomed->year) {
  144. before = maybe_doomed;
  145. maybe_doomed = maybe_doomed->next;
  146. }
  147. if(maybe_doomed->year == y)
  148. {
  149. before->next = maybe_doomed->next;
  150. doomed_node = maybe_doomed;
  151. }
  152. }
  153. delete doomed_node;
  154. return;
  155. }
  156.  
  157. Node* Flowlist::find_year(int y)
  158. {
  159. int i = 0;
  160. search = headM;
  161. while(search != 0)
  162. {
  163. int x = get_year(i);
  164. if (x == y)
  165. {
  166. break;
  167. }
  168. search = search->next;
  169. i++;
  170. }
  171. return search;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement