Help with loop : (

Nestharus

o-o
Reaction score
84
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
Seems like you're missing a sound reverse-lookup method. I wrote a new List library which runs based off of Table that allows insertion in arbitrary points and iterate backwards if necessary, but essentially this would mean you can have an unlimited linked-list for your data structure to work with.

Resp
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 : (.

Super Good
I am sorry but I do not understand what you are after. It may not even be the best structure to solve the problem you have for all we know.

Resp
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.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top