← 返回 apple 的题目列表Implement an Iterator Interface
类型:online_judge
Implement an iterator interface. The interface should support the following methods:
hasNext(): Returns a boolean indicating if there is another element in the iterator.
next(): Returns the next element in the iterator.
remove(): Removes the current element.
Implement this interface using a LinkedList, support generic types, and handle exceptions. Define a Node class, implement the above methods, and test in the main function.
Example
Given a linked list [1, 2, 3], using the iterator to traverse should return [1, 2, 3]. Calling remove() should correctly remove the current element.
Considerations
Provide appropriate exception handling logic.
Implement the interface logic completely and provide test cases.
Example
Input
1->2->3