Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. #include <iostream>
  2. #include "GeneralizedList.h"
  3.  
  4. using namespace std;
  5.  
  6. GeneralizedList::~GeneralizedList()
  7. {
  8. }
  9.  
  10. GeneralizedList::GeneralizedList()
  11. {
  12. List = NULL;
  13. }
  14.  
  15. GeneralizedList::GeneralizedList(Pixel pxl)
  16. {
  17. List = new GenListNode;
  18. List->isList;
  19. List->Item.x = pxl.x;
  20. List->Item.y = pxl.y;
  21. }
  22.  
  23. GeneralizedList::GeneralizedList(GenListNode *subList)
  24. {
  25. List = new GenListNode;
  26. List->Next = NULL;
  27. List->sublist = subList;
  28. }
  29.  
  30. void GeneralizedList::AddAtom(Pixel pxl)
  31. {
  32. GenListNode *pCurr, *pNew;
  33.  
  34. pCurr = List;
  35.  
  36. if(List == NULL)
  37. {
  38. List = new GenListNode;
  39. List->isList = 0;
  40. List->Item.x = pxl.x;
  41. List->Item.y = pxl.y;
  42. List->Next = NULL;
  43. }
  44. else
  45. {
  46. while(pCurr->Next != NULL)
  47. {
  48. pCurr = pCurr->Next;
  49. }
  50.  
  51. pNew = new GenListNode;
  52. pNew->isList = 0;
  53. pNew->Item.x = pxl.x;
  54. pNew->Item.y = pxl.y;
  55. pNew->Next = NULL;
  56.  
  57. pCurr->Next = pNew;
  58. }
  59. }
  60.  
  61. void GeneralizedList::AddSubList(GenListNode *subList)
  62. {
  63. GenListNode *pCurr, *pNew;
  64. pCurr = List;
  65.  
  66. if(List == NULL)
  67. {
  68. List = new GenListNode;
  69. List->isList = 1;
  70. List->sublist = subList;
  71. List->Next = NULL;
  72. }
  73. else
  74. {
  75. while(pCurr->Next != NULL)
  76. {
  77. pCurr = pCurr->Next;
  78. }
  79.  
  80. pNew = new GenListNode;
  81. pNew->isList = true;
  82. pNew->sublist = subList;
  83. pNew->Next = NULL;
  84.  
  85. pCurr->Next = pNew;
  86. }
  87. }
  88.  
  89. int GeneralizedList::Length()
  90. {
  91. GenListNode *pCurr;
  92. int length = 0;
  93.  
  94. pCurr = List;
  95.  
  96. while(pCurr != NULL)
  97. {
  98. if(pCurr->isList)
  99. {
  100. length += Length(pCurr->sublist);
  101. }
  102. else
  103. {
  104. length += 1;
  105. }
  106.  
  107. pCurr = pCurr->Next;
  108. }
  109.  
  110. return length;
  111. }
  112.  
  113. int GeneralizedList::Length(GenListNode *subList)
  114. {
  115. GenListNode *pCurr = subList;
  116. int length = 0;
  117.  
  118. while(pCurr != NULL)
  119. {
  120. if(pCurr->isList)
  121. {
  122. Length(pCurr->sublist);
  123. }
  124. else
  125. {
  126. length += 1;
  127. }
  128.  
  129. pCurr = pCurr->Next;
  130. }
  131.  
  132. return length;
  133. }
  134.  
  135. void GeneralizedList::Traverse()
  136. {
  137. GenListNode *pCurr = List;
  138.  
  139. while(pCurr != NULL)
  140. {
  141. if(pCurr->isList)
  142. {
  143. Traverse(pCurr->sublist);
  144. }
  145. else
  146. {
  147. cout << "(" << pCurr->Item.x << ", " << pCurr->Item.y << ")";
  148. }
  149.  
  150. pCurr = pCurr->Next;
  151. }
  152. }
  153.  
  154. void GeneralizedList::Traverse(GenListNode *subList)
  155. {
  156. GenListNode *pCurr = subList;
  157.  
  158. while(pCurr != NULL)
  159. {
  160. if(pCurr->isList)
  161. {
  162. Traverse(pCurr->sublist);
  163. }
  164. else
  165. {
  166. cout << "(" << pCurr->Item.x << ", " << pCurr->Item.y << ")";
  167. }
  168.  
  169. pCurr = pCurr->Next;
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement