Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. Note: See "linktester.cpp" for more information.
  2. */
  3.  
  4. /*--- LinkedList.h --------------------------------------------------------
  5. This header file contains the declarations of LinkedList, a class for
  6. singly-linked lists.
  7.  
  8. Written by: Larry R. Nyhoff
  9. Written for: Lab Manual for ADTs, Data Structures, and Problem
  10. Solving with C++, 2E
  11.  
  12. Lab #5.1 and Projects 5.1 & 5.2
  13.  
  14. Add a list of the basic operations including brief descriptions.
  15.  
  16. Add your name here and other info requested by your instructor.
  17.  
  18. --------------------------------------------------------------------------*/
  19.  
  20. #ifndef LINKEDLIST
  21. #define LINKEDLIST
  22.  
  23. #include <iostream>
  24. using namespace std;
  25.  
  26. //----- Add typdef statement here
  27. typedef int Number;
  28.  
  29. class LinkedList
  30. {
  31. public:
  32.  
  33.  
  34. //------ LinkedList OPERATIONS
  35.  
  36.  
  37. // Prototype the class constructor here
  38. /* --- LinkedList constructor --------------------------------------
  39. Constructs an empty LinkedList object.
  40.  
  41. Precondition: None.
  42. Postcondition: This list's data members have been initialized
  43. for an empty list.
  44. ---------------------------------------------------------------------*/
  45. LinkedList();
  46.  
  47. // Prototype and document the size() operation here
  48. /*
  49. The size function will return the current value in mySize.
  50. */
  51.  
  52. int size();
  53.  
  54.  
  55. // Prototype and document display() here
  56. /*
  57. The display function will traverse the linked list and display each item.
  58. */
  59. void display(ostream & out) const;
  60.  
  61.  
  62. // Prototype insert() here\
  63.  
  64. void insert(int, int);
  65.  
  66. /*----------------------------------------------------------------------
  67. Insert a value into a LinkedList at a given index.
  68.  
  69. Precondition: The first parameter, index, is an unsigned value with
  70. 0 <= index <= mySize; the second parameter, dataValue, is an
  71. ElementType value. index = 0 denotes insertion at the beginning
  72. of the list, and index = mySize denotes insertion at the end
  73. (after the current last element).
  74. Postcondition: dataValue has been inserted into this LinkedList
  75. object at the position determined by index (provided index
  76. is a legal position).
  77. -----------------------------------------------------------------------*/
  78.  
  79. // Prototype erase() here
  80.  
  81. /*----------------------------------------------------------------------
  82. erase() removes a value from a LinkedList at a given index.
  83.  
  84. Precondition: The parameter index, an unsigned value, satisfies
  85. 0 <= index < mySize.
  86. Postcondition: The data value at the position determined by index
  87. (provided index is a legal position) has been removed from
  88. this LinkedList object.
  89. -----------------------------------------------------------------------*/
  90.  
  91. void erase(int);
  92.  
  93.  
  94. // Prototype and document the destructor here
  95. /*
  96. The destructor simply deallocates each node in the list.
  97. */
  98. ~LinkedList();
  99.  
  100.  
  101. // Prototype and document the copy constructor here
  102. LinkedList(const LinkedList & origList);
  103.  
  104.  
  105. // Prototype and document the assignment operator here
  106. LinkedList& LinkedList::operator=(const LinkedList& list);
  107. private:
  108. class Node
  109. {
  110. public:
  111.  
  112.  
  113. //------ DATA MEMBERS OF Node
  114. // Define data and next members here
  115. Number data;
  116. Node * next;
  117.  
  118.  
  119. //------ Node OPERATIONS
  120.  
  121. // Prototype the Node constructor here
  122. Node(int);
  123.  
  124. /* --- The Node class constructor initializes a Node's data members.
  125.  
  126. Precondition: None
  127. Receive: dataValue, an ElementType value;
  128. Postcondition: The data and next members have been set to
  129. dataValue and 0, respectively.
  130. -------------------------------------------------------------------*/
  131.  
  132. }; //--- end of Node class
  133.  
  134.  
  135.  
  136. typedef Node * NodePointer;
  137.  
  138.  
  139. //------ DATA MEMBERS OF LinkedList
  140. // declare first as a pointer to a Node and declare mySize
  141. NodePointer first;
  142. int mySize;
  143.  
  144.  
  145. }; //--- end of LinkedList class
  146.  
  147. // Put prototype of operator<<() here
  148.  
  149. ostream & operator<< (ostream & out, const LinkedList &list);
  150.  
  151.  
  152.  
  153.  
  154. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement