Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Parent->Children->Children (Pointers)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Flikerator




PostPosted: Mon Feb 26, 2007 5:03 pm   Post subject: Parent->Children->Children (Pointers)

I remember pointers a tad (Currently reading the Pointer tutorial) but while I do that I thought I would throw this out here in case I'm on the wrong path.

Basically what I'm trying to do is form a list. I have a list of names and each name has a list of its children and they all have a list of their children and so on. I was considering doing something like;

code:
var Parent : collection of
    record
        name : string
        child : array 1 .. 1000 of pointer to Parent
        nofchildren : int
    end record
var Root_Parent : pointer to Parent


So each child can have children (1000 for now, thats the limit of children. Although a flexible array could work, I thought I would work on POINTERS first and then work on that later).

So you have the Root and it stores that roots name, along with an array of its children that can all have children. Reading through the tutorial I might use ID's to identify parents or whatever, but for now just wondering if this could work? I've never used pointers before (to any real extent, I've copy and pasted and messed around a bit).

If you've done something like this and have any helpful tips I'd appreciate it.
Sponsor
Sponsor
Sponsor
sponsor
Flikerator




PostPosted: Mon Feb 26, 2007 6:25 pm   Post subject: Re: Parent->Children->Children (Pointers)

Alright so I've been working on it a bit, and I don't know if I'm close or waaaaaaaaaaaay off.

code:
var Parent : collection of
    record
        name : string
        hmmm : pointer to Parent
        child : array 1 .. 10 of pointer to Parent
        nochild : int
    end record
var home : pointer to Parent
new Parent, home

Parent (home).name := "High"
put home -> name
put Parent (home).name

new Parent, Parent (home).hmmm

Parent (home).hmmm -> name := "hello"
home -> hmmm -> name := "hello2"
put Parent (home).hmmm -> name

new Parent, Parent (home).child (1)
home -> child (1) -> name := "child"
put home -> child (1) -> name
put index ("When the child is away, the parents will pwn n0obz", Parent (home).child (1) -> name)

Input.Pause
cls
/*-------------------------*/

var root : ^Parent
new Parent, root
root -> name := "Charley"
root -> nochild := 0

%NEW Child for ROOT (Charley)
root -> nochild += 1
new Parent, root -> child (root -> nochild) %Declares the new child of root in entry of the new child, nochild
root -> child (root -> nochild) -> name := "Stanley"
root -> child (root -> nochild) -> nochild := 0


The top was me just messing around. The bottom is what I'm working on. So it creates the main head person and names him child with NO children. BAM he has a child, so we create a new child. His child is given the name Stanley. The process could be repeated, but just for one more child it gets long (and confusing). There is probably an easier/possible way to do it. Im still working on it, let me know if you can help.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: