- iterator reset on all structures

This commit is contained in:
Emir Pasic
2016-06-26 20:50:49 +02:00
parent d5a7c62629
commit b86d413e66
10 changed files with 73 additions and 0 deletions
+7
View File
@@ -111,6 +111,7 @@ func (stack *Stack) Iterator() Iterator {
// Next moves the iterator to the next element and returns true if there was a next element in the container.
// If Next() returns true, then next element's index and value can be retrieved by Index() and Value().
// If Next() was called for the first time, then it will point the iterator to the first element if it exists.
// Modifies the state of the iterator.
func (iterator *Iterator) Next() bool {
if iterator.index < iterator.stack.Size() {
@@ -142,6 +143,12 @@ func (iterator *Iterator) Index() int {
return iterator.index
}
// Reset sets the iterator to the initial state.
// Call Next() to fetch the first element if any.
func (iterator *Iterator) Reset() {
iterator.index = -1
}
// String returns a string representation of container
func (stack *Stack) String() string {
str := "ArrayStack\n"