Quote (KrzaQ2 @ Jun 17 2014 05:31am)
How can you go deeper iteratively?
Could iterate storing details each complete iteration eventually building a tree couldn't you?
Something like
Quote
<html>
<head>
<title>test</title>
<head>
<body>
<p>paragraph</p>
<h1>header</h1>
</body>
</html>
First complete iteration will find all nodes below HTML (head, body) stored to a list or array for processing until all the current levels nodes have been found.
so tree would look like
Quote
HTML [head, body]
/ \
head body
Next you would iterate again but find the next depth to iterate which would be head which was the first to be found, and stored in the list/array. It would first look for new nodes, if any were to be found create an array/list of them to be further searched, if not store the data contained in that node.
Quote
HTML [head[title], body]
/ \
head body
| |
title
/
"test"
Then you would do this again but this time it would result in searching title for new nodes, but none will be found so its data "Test" would be added.
Then you can remove the head node from your list/array because you completely searched it and process your next node in the array/list body, which it would find two nodes to process while iterating. From there it would process again and will either search for more nodes or their data.
Quote
HTML
/ \
head body [body[h1, p]]
| | \
title
/
"test"
End result would be something like this
Quote
HTML
/ \
head body
| | \
title h1 p
/ | \
"test" "header" "paragraph"
Is this idea any better than recursion hell if I know. I just dislike recursion because I'm not bright enough to use it for complex needs.