fork download
  1. #include "list.h"
  2.  
  3. /*
  4. constructor's purpose is to make nodes i.e. dynamic variables containing 1
  5. or more values and a pointer variable that references the next node, else NULL
  6. */
  7.  
  8. Node::Node(int _val, Node* _next)
  9. {
  10. next = _next;
  11. value = _val;
  12. }
  13.  
  14. Node* Node::prefix(int value, Node* head)
  15. {
  16. head = new Node(value,head);
  17. return head;
  18. }
  19.  
  20.  
  21. Node* Node::searchElem(Node* head,int searchKey)
  22. {
  23. Node* trav = head;
  24. while(searchKey != trav->getValue() && trav->getNext() != NULL)
  25. trav = trav->getNext();
  26.  
  27. if( searchKey == trav->getValue() )
  28. return trav;
  29. else
  30. return NULL;
  31. }
  32.  
  33.  
  34.  
  35. /*
  36. FUNCTION: appends in the middle or at the end of a linked list
  37. INPUT:
  38. 1. pointer to the previous node you are appending to
  39. 2. the value contained in the successive node you are appending
  40. */
  41. void Node::insert(Node* prev, int value)
  42. {
  43. prev->setNext(new Node(value,prev->next));
  44. }
  45.  
  46. /*
  47. FUNCTION: removes a node and deallocates the memory assigned to its dynamic variable
  48. INPUT:
  49. 1. pointer to the previous node
  50. 2. pointer to the node we would like to remove
  51. */
  52. void Node::remove(Node* prev, Node* target)
  53. {
  54. prev->next = target->next;
  55. delete target;
  56. /*
  57.   memory allocated to dynamic variables comes from the freestore area of main memory which is limited, for this reason we use delete to restore/deallocate the memory used to the operating system which governs the freestore so we can use this memory for other processes
  58.   */
  59. }
  60.  
  61. int Node::getValue()
  62. const
  63. {
  64. return value;
  65. }
  66.  
  67. Node* Node::getNext()
  68. const
  69. {
  70. return next;
  71. }
  72.  
  73. void Node::setValue(int _value)
  74. {
  75. value = _value;
  76. }
  77.  
  78. void Node::setNext(Node* _next)
  79. {
  80. next = _next;
  81. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:18: fatal error: list.h: No such file or directory
compilation terminated.
stdout
Standard output is empty