/** * @fileOverview Implementation of an iterator for a linked list * data structure * @author Jason S. Jones * @license MIT */ import LinkedList from '../index'; import ListNode from './list-node'; /** * Iterator class * * Represents an instantiation of an iterator to be used * within a linked list. The iterator will provide the ability * to iterate over all nodes in a list by keeping track of the * postition of a 'currentNode'. This 'currentNode' pointer * will keep state until a reset() operation is called at which * time it will reset to point the head of the list. * * Even though this iterator class is inextricably linked * (no pun intended) to a linked list instantiation, it was removed * from within the linked list code to adhere to the best practice * of separation of concerns. * */ declare class ListIterator { list: LinkedList; currentNode: ListNode; /** * Creates an iterator instance to iterate over the linked list provided. * * @constructor * @param {object} theList the linked list to iterate over */ constructor(theList: LinkedList); next(): ListNode; /** * Determines if the iterator has a node to return * * @returns true if the iterator has a node to return, false otherwise */ hasNext(): boolean; /** * Resets the iterator to the beginning of the list. */ reset(): void; /** * Returns the first node in the list and moves the iterator to * point to the second node. * * @returns the first node in the list */ first(): ListNode; /** * Sets the list to iterate over * * @param {object} theList the linked list to iterate over */ setList(theList: LinkedList): void; /** * Iterates over all nodes in the list and calls the provided callback * function with each node as an argument. * * @param {function} callback the callback function to be called with * each node of the list as an arg */ each(callback: (node: ListNode) => void): void; } export default ListIterator;