Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. #include "BballRoster.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. BballRoster::BballRoster()
  6. {
  7. head = nullptr;
  8. tail = nullptr;
  9.  
  10.  
  11.  
  12. }
  13.  
  14.  
  15. bool BballRoster::rosterEmpty() const
  16. {
  17. Node* p;
  18. p = head;
  19. int i = 0;
  20. while (p != nullptr)
  21. {
  22.  
  23. p = p->next;
  24. i++;
  25. }
  26.  
  27. if (i == 0)
  28. {
  29. return true;
  30. }
  31. else
  32. {
  33. return false;
  34. }
  35.  
  36. }
  37.  
  38.  
  39. int BballRoster::howManyPlayers() const
  40. {
  41. Node* p;
  42. p = head;
  43. int i = 0;
  44. while (p != nullptr)
  45. {
  46.  
  47. p = p->next;
  48. i++;
  49. }
  50.  
  51.  
  52.  
  53. return i;
  54.  
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. bool BballRoster::signPlayer(const std::string& firstName, const std::string&lastName, const SomeType& value)
  62. {
  63. //put data into node
  64. Node* p;
  65. p = new Node;
  66. p->firstname = firstName;
  67. p->lastname = lastName;
  68. p->value = value;
  69.  
  70. //create unsorted linked list
  71. if (rosterEmpty() == true)
  72. {
  73. head = p;
  74. tail = p;
  75. head->next = nullptr;
  76. p->prev = nullptr;
  77. }
  78. else {
  79.  
  80. tail->next = p;
  81. p->prev = tail;
  82. tail = p;
  83. tail->next = nullptr;
  84.  
  85. }
  86.  
  87. //sort linked list
  88. Node* n;
  89. Node* k;
  90. string temp;
  91. string temp2;
  92. string temp3;
  93.  
  94. for (n = head->next; n != nullptr; n = n->next)
  95. {
  96. for (k = head; k != nullptr; k = k->next)
  97. {
  98. if (n->lastname < k->lastname)
  99. {
  100. temp = n->lastname;
  101. temp2 = n->firstname;
  102. temp3 = n->value;
  103.  
  104. n->lastname = k->lastname;
  105. n->firstname = k->firstname;
  106. n->value = k->value;
  107. k->lastname = temp;
  108. k->firstname = temp2;
  109. k->value = temp3;
  110. }
  111. else if (n->lastname == k->lastname)
  112. {
  113. if (n->firstname < k->firstname)
  114. {
  115. temp = n->lastname;
  116. temp2 = n->firstname;
  117. temp3 = n->value;
  118.  
  119. n->lastname = k->lastname;
  120. n->firstname = k->firstname;
  121. n->value = k->value;
  122. k->lastname = temp;
  123. k->firstname = temp2;
  124. k->value = temp3;
  125. }
  126.  
  127. }
  128. }
  129.  
  130. }
  131.  
  132.  
  133.  
  134.  
  135. return true;
  136. }
  137.  
  138. bool BballRoster::resignPlayer(const std::string& firstName, const std::string&lastName, const SomeType& value)
  139. {
  140.  
  141.  
  142. return false;
  143. }
  144.  
  145. bool BballRoster::signOrResign(const std::string& firstName, const std::string&lastName, const SomeType& value)
  146. {
  147.  
  148.  
  149. return false;
  150. }
  151.  
  152. bool BballRoster::renouncePlayer(const std::string& firstName, const std::string& lastName)
  153. {
  154.  
  155. return false;
  156. }
  157.  
  158. bool BballRoster::playerOnRoster(const std::string& firstName, const std::string& lastName) const
  159. {
  160.  
  161.  
  162. return false;
  163. }
  164.  
  165. bool BballRoster::lookupPlayer(const std::string& firstName, const std::string&lastName, SomeType& value) const
  166. {
  167.  
  168.  
  169. return true;
  170. }
  171.  
  172. bool BballRoster::choosePlayer(int i, std::string& firstName, std::string&lastName, SomeType& value) const
  173. {
  174.  
  175.  
  176. return true;
  177. }
  178.  
  179.  
  180. void BballRoster::swapRoster(BballRoster& other)
  181. {
  182.  
  183.  
  184. }
  185.  
  186. void BballRoster::printRoster()
  187. {
  188. Node* p = new Node;
  189. p = head;
  190. while (p != nullptr)
  191. {
  192. cout << p->lastname << " " << p->firstname << " " << p->value << endl;
  193. p = p->next;
  194. }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement