SHARE
TWEET

Untitled

a guest Jun 16th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. List::List()
  2. {
  3. HeadNode = new Node();
  4. HeadNode->SetNext(nullptr);
  5. CurrentNode = nullptr;
  6. LastCurrentNode = nullptr;
  7. Size = 0;
  8. }
  9.  
  10. void List::Add(int AddObject)
  11. {
  12. Node* NewNode = new Node();
  13. NewNode->Set(AddObject);
  14. if (CurrentNode != nullptr)
  15. {
  16.     NewNode->SetNext(CurrentNode->GetNext());
  17.     CurrentNode->SetNext(NewNode);
  18.     LastCurrentNode = CurrentNode;
  19.     CurrentNode = NewNode;
  20. }
  21. else
  22. {
  23.     NewNode->SetNext(nullptr);
  24.     HeadNode->SetNext(NewNode);
  25.     LastCurrentNode = HeadNode;
  26.     CurrentNode = NewNode;
  27. }
  28. Size++;
  29. }
  30.  
  31. int List::Get()
  32. {
  33. if (CurrentNode != nullptr)
  34. {
  35.     return CurrentNode->Get();
  36. }
  37. }
  38.  
  39. bool List::Next()
  40. {
  41. if (CurrentNode == nullptr)
  42. {
  43.     return false;
  44. }
  45. LastCurrentNode = CurrentNode;
  46. CurrentNode = CurrentNode->GetNext();
  47. if ((CurrentNode == nullptr) || (Size = 0))
  48. {
  49.     return false;
  50. }
  51. else
  52. {
  53.     return true;
  54. }
  55. }
  56.  
  57. void List::Remove()
  58. {
  59. if (CurrentNode != nullptr && CurrentNode != HeadNode)
  60. {
  61.     LastCurrentNode->SetNext(CurrentNode->GetNext());
  62.     delete CurrentNode;
  63.     CurrentNode = LastCurrentNode->GetNext();
  64.     Size--;
  65. }
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top