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

Username:   Password: 
 RegisterRegister   
 Text-Based Adventure I was working on last year, figured I'd look over it and ask for some opinions on it
Index -> Programming, Turing -> Turing Submissions
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Raknarg




PostPosted: Mon Jun 04, 2012 8:01 pm   Post subject: Re: Text-Based Adventure I was working on last year, figured I'd look over it and ask for some opinions on it

haha there's too many users too remember XD hello again though.

So basically I like to consider them as arrays with multiple directions. They can work in different ways. For instance, you could just imagine a chain, where one link is touch the next link and the one before it, or a tree where each link is holding two links below it, and you have one original link at the top. In this case, you could do something like the tree one. I'll tell you a bit about the first one.

You would start with this:
Turing:

var link : collection of
    record
        previous, next : ^link
        contents : string
    end record

var current : ^ link
new link, current
current -> previous := nil
current -> next := nil


So look at what we have here. There's a collection with three things: a pointer to the next link, a pointer to the previous link and a contents variable that'll hold some info. So far there is only one link, so we say that the current and next links have nothing, i.e. nil. There are different ways to go about doing this, but this is what I do. Now lets say we wanted to move to the next link in the chain. We would do this:

Turing:

new link, current -> next
current -> next -> previous := current
current := current -> next


This might look a bit confusing, so we'll break it down. First we initialize the pointer next so we can use it. (Idk if that's necessary, I'm just used to classes. Kindof similar in turing). Then we have this statement:

current -> next -> previous := current

In other words, we want what the previous of whatever next is to be whatever you're at now. If you just tried to move on to next without this statement, previous would have nothing in it, and so you would lose current. The idea of a linked list is to have everything linked, remember?

current := current -> next

We want current to now be on the next link. Pretty straightforward.

So it might be a bit confusing, but it can come in handy sometimes. I'll show you a game I made with this idea.



Linked Lists - 20 Questions.t
 Description:

Download
 Filename:  Linked Lists - 20 Questions.t
 Filesize:  1.7 KB
 Downloaded:  116 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 16 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: