Data Structures AND Algorithms: Lecture Notes 6
Data Structures AND Algorithms: Lecture Notes 6
DATA STRUCTURES
AND
ALGORITHMS
Lecture Notes 6
Sequential Containers
Spring 2008
// Constructor
/** Creates a new Node that points to another Node.
@param data_item The data stored
@param next_ptr pointer to the Node that is
pointed to by the new Node
*/
Node(const Item_Type&
Item_Type& data_item,
data_item, Node* next_ptr = NULL) :
data(data_item),
data(data_item), next(next_ptr)
next(next_ptr) {}
};
#endif
// Constructor
/** Creates a new Node that points to another Node.
@param data_item The data stored
@param next_ptr pointer to the Node that is
pointed to by the new Node
*/
Node(const Item_Type&
Item_Type& data_item,
data_item,
Node* next_ptr = NULL Node* prev_ptr = NULL) :
data(data_item),
data(data_item), next(next_ptr),
next(next_ptr), perv(prev_ptr)
perv(prev_ptr) {}
};
#endif
iterator&
iterator& operator--
operator--()
--() {
if (current == parent-
parent->head)
throw std::invalid_argument("Attempt to move before begin()");
if (current == NULL) // Past last element.
current = parent-
parent->tail;
else
current = current-
current->prev;
prev;
return *this;
}
iterator operator--
operator--(
--(Item_Type)
Item_Type) {
// Make a copy of the current value.
iterator return_value = *this;
// Move self backward.
--(*this);
--(*this);
// Return old value.
return return_value;
return_value; // Return the value prior to decrement
}