📄 listi.h
字号:
// *********************************************************// Header file ListI.h for the ADT list.// Implementation uses ListIterator.// *********************************************************#include "ListIterator.h"#include "ListException.h"class List{public:// constructors and destructor: List(); List(const List& aList); ~List();// List operations: bool isEmpty() const; int getLength() const; ListIterator insert(ListIterator iter, ListItemType newItem) throw(ListException); // Inserts an item into a list after the item // specified by iter. An iterator to the newly // added item is returned. // Precondition: Iterator iter specifies either an // item in the list or the end of the list. // Postcondition: If iter equals the value returned // by end(), newItem is placed at the end of the // list. Returns an iterator to newItem within the list. // Exception: Throws ListException if the iterator is // not initialized properly for this list. void retrieve(ListIterator iter, ListItemType& dataItem) const throw(ListException); // Retrieves an item in the list. // Precondition: Iterator iter specifies an item in // the list. // Postcondition: dataItem is the value of the // desired item. // Exception: Throws ListException if the iterator is // not initialized properly for this list. ListIterator remove(ListIterator iter) throw(ListException); // Removes an item from the list and returns an // iterator to the item after the removed item. // Precondition: Iterator iter specifies an item in // the list. // Postcondition: The item specified by iter is // removed from the list. Returns an iterator that // references the item after the one removed. If the last // item in the list is removed, returns an iterator that // is equal to the result returned by end(). // Exception: Throws ListException if the iterator is // not initialized properly for this list. ListIterator begin() const; // Returns an iterator that references the first item // in the list. // Precondition: None. // Postcondition: Returns an iterator to the first // item in the list. If the list is empty, returns an // iterator that is equal to the result returned by end(). ListIterator end() const; // Returns an iterator value that can be used to // determine whether an iterator has reached the end // of the list. // Precondition: None. // Postcondition: Noneprivate: int size; // number of items in the list ListNode *head; // pointer to the linked list ListNode *findPrev(ListIterator iter); // Locates the node before the node specified by iter. // Precondition: The list is not empty (head != NULL). // Postcondition: Returns a pointer to the node // before the node referenced by iter. If iter == end(), // returns a pointer to the last node in the list.}; // end class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -