Help with a loop : (

Status
Not open for further replies.
So I've been trying to solve this for like 20 hours now and still can't solve.

I am looping over this type of structure (although it is unknown what's in it).

Code:
head
    link (points to head)
        pointer (points to 0)
            link (points to pointer)
                val (points to 0)
                    link (points to val)
                       val (points to 0)
            link (points to pointer)
                val (points to 0)
                    link (points to val)
                       val (points to 0)
            link (points to pointer)
                val (points to 0)
                    link (points to val)
                       val (points to 0)
    link
        val (points to 0)

The data I showed is entirely random. What is known is that there is a link connecting everything together. It will always go link -> (pointer | val).

Pointers are nodes that are automatically skipped over and are never seen.

Values are there for writing data
Links look at the current parent depth's value. If the value is in the range of the link, then it goes inside of the link.

Code:
Value (15)
    Link (0 to 15) (go inside)
    Link (20 to 30) don't go in)
    Link (15 to 15) (go in)

And within the links, there could be any number of pointers.

The loop I am using to go through this data structure just contains 2 operators and 1 method-

get (get the next node, could be from anywhere but it is the next node in the structure)

skip (skips the current node, meaning it skips all contents in it)

end (end the loop)

So, if the value doesn't fit into the link, skip is used. If the value does fit, get is used to actually get to the val inside and skip isn't used. On every iteration, get is used at the very beginning to get the next node.


While this seems pretty straight forward and easy so far, it really isn't. I need to know what the current parent depth's value is. I am currently using a stack to stack values on to each other. When I go deeper, I add to the stack and update the value. When I go out, I pop off from the stack. Again, straight forward, but I could be going out any amount.

To see how far to go out, I go out until the current stored parent link matches the current link's parent.

Remember along a column, all links share the same parent.

Code:
parent
    link
    link
    link
    link

All 4 of those links would have the same exact parent. If I went out of parent and into a whole different parent, it'd end up going to the very top (stack would be empty) and then would add on to the stack.

Seems good so far still right?

The problem is that my current method can't retrieve the parent until after** skipping occurs. This means that this can happen

get (go deeper)
skip (uh oh, no parents match, so ends up going to the very top)


The problem with get is that it could either end up going deeper or going out or w/e. Checking to see if the next node's parent matches with the current depth link does see if the current depth is the same, but if it isn't, you have no idea whether you went up or down because links will point to value nodes and value node parents are 0. For every node, there are only 2 possible connections (excluding pointers, which don't matter)

link.root = parent

So... I'm struggling with determining how to update the depth w/o access to the loop method : (.

Any ideas?

Code:
    get next node

    loop
        exitwhen not a link

        loop
            exitwhen not link or fits or 0
            skip link
            loop
                exitwhen depth parents match (this is where bug of 0 can happen)
            endloop
        endloop

        if link, add to depth stack
    endloop

That's what my loop structure looks like where get and skip are methods.

So... from what I see, the only way to fix the bug is update the depth stack upon the retrieval of the next node as well as skips.

Again, the problem is I don't know (when the depth is different) where I am : O. I've been straining over this problem for so long and really need help with it. The only possible thing I can think of is to code the get/skip looping stuff from scratch so that I can update the depths in there (inside of there, I'd def know, but it's a lot of code and it's really, really ugly, so I really don't want to do it).

Tx for your help ;D.
 
Bribe... there is a reason that there is no parent node.

Didn't you see the links ; P.

Let's say all of these are the exact same node
->val (points to 0)

And all of the Links are unique nodes.

A node can't have multiple parents >.>, hence why all val nodes point to 0 rather than the links.

So I'm guessing I'll have to code this loop from scratch : (.
 
I don't see how that'd work. If you had a single node pointing to a set of parents, how would you know which parent was the right one?

Also, the links are actually pointers to other trees, so it makes sense that those other trees point to 0, heh.

What I'm actually doing with the loop is building like a virtual tree, building all of the parents to each node as I go along (as the depth increases, update the parent).

The prob I'm having is that I don't know whether I'm going up or down when I use the get ;P.
 
It is the best ;).

I just want to be able to go through it step by step and be able to know what the current link is (pointer parent) and the current node is.

Like I keep saying, my prob is that when I use the get method (for getting the next node in the tree), I don't know whether it's going deeper in or out, so I have no clue how to update the current link depth.

For storing the linnks, I'm using a stack. When I go deeper, I add to the stack. When I go out, I remove from the stack.
 
Status
Not open for further replies.
Top