fork download
  1. //
  2. // list.cpp
  3. // NodeTutorHelp
  4. //
  5. // Created by Kurtis on 3/25/13.
  6. // Copyright (c) 2013 Kurtis. All rights reserved.
  7. //
  8.  
  9. #include "list.h"
  10. #include "node.h"
  11. #include <iostream>
  12. using namespace std;
  13.  
  14.  
  15. //CONSTRUCTOR/DESTRUCTOR
  16.  
  17. list::list()
  18. {
  19.  
  20. head = NULL;
  21.  
  22.  
  23. }
  24.  
  25.  
  26.  
  27. list::~list() // called when object goes out of scope
  28.  
  29. {
  30. node *cursor = head;
  31.  
  32. while (cursor != NULL)
  33. {
  34. node *nextNode = cursor->link_field;
  35. delete cursor;
  36. cursor = nextNode;
  37.  
  38. }
  39.  
  40. head = NULL;
  41.  
  42. }
  43.  
  44. // MEMBER FUNCTIONS
  45. void list::insert_front(const double valueToAdd)
  46. {
  47. node* newNode = new node(valueToAdd, NULL); // create a new node to add to the list
  48. newNode->link_field = head; //set new node's data field to the rest of the list
  49. head = newNode;
  50.  
  51. }
  52.  
  53.  
  54. void list::removeDublicateEntries()
  55. {
  56. node * cursorOne = head;
  57. node * cursorTwo = head->link_field;
  58.  
  59.  
  60. while(cursorOne != NULL)
  61. {
  62. cout << "enter first loop" << endl;
  63. if (cursorOne)
  64. cout << "cursor 1: " << cursorOne->data_field <<endl;
  65.  
  66.  
  67. while(cursorTwo != NULL)
  68. {
  69. cout << "Enter Second Loop" << endl;
  70. cout << cursorTwo->data_field << " Curse 2" << endl;
  71.  
  72. //compare it
  73. if (cursorOne->data_field == cursorTwo->data_field)
  74. {
  75.  
  76. //prev->next = current->next to delete
  77. // in order to delete only one, I must find a way to set the link_field of the previous node to cursor 1 to
  78. // the link field of the node that's to be deleted
  79. cout << cursorOne->data_field << "being removed" << endl;
  80. cursorOne->link_field = cursorTwo->link_field; //if they are the same, cursor1 link field must point to cursorTwo's
  81. cursorTwo = NULL;
  82.  
  83.  
  84. delete cursorTwo; //delete the node that cursor2 is pinting at if its the same as cursor1
  85. cursorTwo = cursorOne; //set cursor2 to cursor1
  86.  
  87. }
  88. cursorTwo = cursorTwo->link_field;
  89. }
  90. cursorOne = cursorOne->link_field;
  91. if (cursorOne)
  92. cursorTwo = cursorOne->link_field;
  93. }
  94.  
  95. }
  96.  
  97.  
  98.  
  99. int list::count() const
  100. {
  101. const node *cursor; //Pointer to a node that
  102. int answer = 0;
  103. for (cursor = head; cursor != NULL; cursor = cursor ->link_field)
  104. ++answer;
  105.  
  106. return answer;
  107.  
  108. }
  109.  
  110. void list::print() const //print current linked list members
  111. {
  112.  
  113. const node *cursor;
  114. for (cursor = head; cursor != NULL; cursor = cursor->link_field)
  115. //set cursor = to data member head, keep going as long as cursor != null, to increment, set cursor to link_field of the node it's currently pointing at for the next node in sequence
  116. cout << cursor->data_field << endl;
  117.  
  118.  
  119. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:9:18: fatal error: list.h: No such file or directory
compilation terminated.
stdout
Standard output is empty