mirror of
https://github.com/Doctorado-ML/STree.git
synced 2025-08-15 23:46:02 +00:00
integrate iterator in Stree
This commit is contained in:
@@ -1,22 +1,34 @@
|
||||
'''
|
||||
__author__ = "Ricardo Montañana Gómez"
|
||||
__copyright__ = "Copyright 2020, Ricardo Montañana Gómez"
|
||||
__license__ = "MIT"
|
||||
__version__ = "0.9"
|
||||
Inorder iterator for the binary tree of Snodes
|
||||
Uses LinearSVC
|
||||
'''
|
||||
|
||||
from trees.Snode import Snode
|
||||
|
||||
|
||||
class Siterator:
|
||||
"""Implements an inorder iterator
|
||||
"""Inorder iterator
|
||||
"""
|
||||
|
||||
def __init__(self, tree: Snode):
|
||||
self._stack = []
|
||||
self._push(tree)
|
||||
|
||||
def hasNext(self) -> bool:
|
||||
return len(self._stack) > 0
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def _push(self, node: Snode):
|
||||
while (node is not None):
|
||||
self._stack.insert(0, node)
|
||||
node = node.get_down()
|
||||
|
||||
def next(self) -> Snode:
|
||||
def __next__(self) -> Snode:
|
||||
if len(self._stack) == 0:
|
||||
raise StopIteration()
|
||||
node = self._stack.pop()
|
||||
self._push(node.get_up())
|
||||
return node
|
||||
|
Reference in New Issue
Block a user