Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Note: See "linktester.cpp" for more information.
- */
- /*--- LinkedList.h --------------------------------------------------------
- This header file contains the declarations of LinkedList, a class for
- singly-linked lists.
- Written by: Larry R. Nyhoff
- Written for: Lab Manual for ADTs, Data Structures, and Problem
- Solving with C++, 2E
- Lab #5.1 and Projects 5.1 & 5.2
- Add a list of the basic operations including brief descriptions.
- Add your name here and other info requested by your instructor.
- --------------------------------------------------------------------------*/
- #ifndef LINKEDLIST
- #define LINKEDLIST
- #include <iostream>
- using namespace std;
- //----- Add typdef statement here
- typedef int Number;
- class LinkedList
- {
- public:
- //------ LinkedList OPERATIONS
- // Prototype the class constructor here
- /* --- LinkedList constructor --------------------------------------
- Constructs an empty LinkedList object.
- Precondition: None.
- Postcondition: This list's data members have been initialized
- for an empty list.
- ---------------------------------------------------------------------*/
- LinkedList();
- // Prototype and document the size() operation here
- /*
- The size function will return the current value in mySize.
- */
- int size();
- // Prototype and document display() here
- /*
- The display function will traverse the linked list and display each item.
- */
- void display(ostream & out) const;
- // Prototype insert() here\
- void insert(int, int);
- /*----------------------------------------------------------------------
- Insert a value into a LinkedList at a given index.
- Precondition: The first parameter, index, is an unsigned value with
- 0 <= index <= mySize; the second parameter, dataValue, is an
- ElementType value. index = 0 denotes insertion at the beginning
- of the list, and index = mySize denotes insertion at the end
- (after the current last element).
- Postcondition: dataValue has been inserted into this LinkedList
- object at the position determined by index (provided index
- is a legal position).
- -----------------------------------------------------------------------*/
- // Prototype erase() here
- /*----------------------------------------------------------------------
- erase() removes a value from a LinkedList at a given index.
- Precondition: The parameter index, an unsigned value, satisfies
- 0 <= index < mySize.
- Postcondition: The data value at the position determined by index
- (provided index is a legal position) has been removed from
- this LinkedList object.
- -----------------------------------------------------------------------*/
- void erase(int);
- // Prototype and document the destructor here
- /*
- The destructor simply deallocates each node in the list.
- */
- ~LinkedList();
- // Prototype and document the copy constructor here
- LinkedList(const LinkedList & origList);
- // Prototype and document the assignment operator here
- LinkedList& LinkedList::operator=(const LinkedList& list);
- private:
- class Node
- {
- public:
- //------ DATA MEMBERS OF Node
- // Define data and next members here
- Number data;
- Node * next;
- //------ Node OPERATIONS
- // Prototype the Node constructor here
- Node(int);
- /* --- The Node class constructor initializes a Node's data members.
- Precondition: None
- Receive: dataValue, an ElementType value;
- Postcondition: The data and next members have been set to
- dataValue and 0, respectively.
- -------------------------------------------------------------------*/
- }; //--- end of Node class
- typedef Node * NodePointer;
- //------ DATA MEMBERS OF LinkedList
- // declare first as a pointer to a Node and declare mySize
- NodePointer first;
- int mySize;
- }; //--- end of LinkedList class
- // Put prototype of operator<<() here
- ostream & operator<< (ostream & out, const LinkedList &list);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement