PurgeandFire
zxcvmkgdfg
- Reaction score
- 509
Well, think of it like this. You have a list:
<HEAD NODE> <NEXT 1> <NEXT 2> <NEXT 3> <NEXT 4>
In this case, the <HEAD NODE> is [ljass]thistype(0)[/ljass]. Then it chains into <NEXT 1, 2, 3, 4>. When we insert an instance, where do we insert it?
<HEAD NODE> <INSERT> <NEXT 1> ...
We will insert it at the beginning right after the head node. It is nice to think of it as a table. What you want to do is make the head think its next is the inserted, inserted think its prev is the head, the inserted think its next is next1, and next1 think its previous is the inserted. At first:
thistype(0)'s next = <NEXT 1>
this' next = Not defined.
this' prev = Not defined.
NEXT 1's prev = thistype(0).
At the moment, it is nothing. So now lets begin the process:
thistype(0)'s next = <NEXT 1>
this' next = Not defined.
this' prev = Not defined.
NEXT 1's prev = this
Now we've made NEXT 1 think its previous is "this". At the moment, thistype(0).next is equal to NEXT 1. Previously thistype(0).next.prev == thistype(0), but now thistype(0).next.prev = this. Basically, NEXT 1's previous is now "this".
thistype(0)'s next = <NEXT 1>
this' next = <NEXT 1>
this' prev = Not defined.
NEXT 1's prev = this
Now we make "this" think its next is NEXT 1. So far, we've made NEXT 1 think it's previous is "this" and "this" think its next is NEXT 1. Now we need to handle the other two parts.
thistype(0).next = this
this' next = <NEXT 1>
this' prev = Not defined.
NEXT 1's prev = this
Now we made the head node think its next (the first instance in the list) is "this". Notice how when you add an instance, it is essentially shifting the order of things. <NEXT 1> now becomes second in the list, <NEXT 2> becomes third, <NEXT 3> becomes fourth, and so on. Think of basically a kindergartner cutting in front of his class in the line for lunch. Everyone's order after him becomes shifted down.
Now we must finish the insert.
thistype(0).next = this
this' next = <NEXT 1>
this' prev = thistype(0)
NEXT 1's prev = this
Now we've officially inserted it. To answer your questions:
1.) Yes.
2.) Yes.
3.) No, you are making thistype(0) think its next instance is "this". =)
4.) Uhmm....
Now, visualizations are key to understanding these concepts.
^ A standard list. It simply shows the order of each item. Starting from the head node, it goes on to 1, 2, 3, and 4.
^ Now a new item comes into the list.
^ The new item doesn't know its identity. The other items are still considered 1, 2, 3, and 4 of the list. The new item is just randomly there. But once he declares himself as part of the list, letting the head node and the next node (in the pic, it is <- == prev node, -> == next node, despite his facing) that he is part of the list. Each item won't really "know" that the new item is there, but I wanted to just show you that once something comes in and is properly inserted, the list will be now ready again.
So it went from 1, 2, 3, and 4 to 1, 2, 3, 4, and 5. Those are just visual numbers, not really meant to signify anything but the literal order of the list.
Hopefully that'll clear some things up.
<HEAD NODE> <NEXT 1> <NEXT 2> <NEXT 3> <NEXT 4>
In this case, the <HEAD NODE> is [ljass]thistype(0)[/ljass]. Then it chains into <NEXT 1, 2, 3, 4>. When we insert an instance, where do we insert it?
<HEAD NODE> <INSERT> <NEXT 1> ...
We will insert it at the beginning right after the head node. It is nice to think of it as a table. What you want to do is make the head think its next is the inserted, inserted think its prev is the head, the inserted think its next is next1, and next1 think its previous is the inserted. At first:
thistype(0)'s next = <NEXT 1>
this' next = Not defined.
this' prev = Not defined.
NEXT 1's prev = thistype(0).
At the moment, it is nothing. So now lets begin the process:
JASS:
set thistype(0).next.prev=this
thistype(0)'s next = <NEXT 1>
this' next = Not defined.
this' prev = Not defined.
NEXT 1's prev = this
Now we've made NEXT 1 think its previous is "this". At the moment, thistype(0).next is equal to NEXT 1. Previously thistype(0).next.prev == thistype(0), but now thistype(0).next.prev = this. Basically, NEXT 1's previous is now "this".
JASS:
set this.next=thistype(0).next
thistype(0)'s next = <NEXT 1>
this' next = <NEXT 1>
this' prev = Not defined.
NEXT 1's prev = this
Now we make "this" think its next is NEXT 1. So far, we've made NEXT 1 think it's previous is "this" and "this" think its next is NEXT 1. Now we need to handle the other two parts.
JASS:
set thistype(0).next=this
thistype(0).next = this
this' next = <NEXT 1>
this' prev = Not defined.
NEXT 1's prev = this
Now we made the head node think its next (the first instance in the list) is "this". Notice how when you add an instance, it is essentially shifting the order of things. <NEXT 1> now becomes second in the list, <NEXT 2> becomes third, <NEXT 3> becomes fourth, and so on. Think of basically a kindergartner cutting in front of his class in the line for lunch. Everyone's order after him becomes shifted down.
Now we must finish the insert.
JASS:
set this.prev=thistype(0)
thistype(0).next = this
this' next = <NEXT 1>
this' prev = thistype(0)
NEXT 1's prev = this
Now we've officially inserted it. To answer your questions:
1.) Yes.
2.) Yes.
3.) No, you are making thistype(0) think its next instance is "this". =)
4.) Uhmm....
Now, visualizations are key to understanding these concepts.
^ A standard list. It simply shows the order of each item. Starting from the head node, it goes on to 1, 2, 3, and 4.
^ Now a new item comes into the list.
^ The new item doesn't know its identity. The other items are still considered 1, 2, 3, and 4 of the list. The new item is just randomly there. But once he declares himself as part of the list, letting the head node and the next node (in the pic, it is <- == prev node, -> == next node, despite his facing) that he is part of the list. Each item won't really "know" that the new item is there, but I wanted to just show you that once something comes in and is properly inserted, the list will be now ready again.
So it went from 1, 2, 3, and 4 to 1, 2, 3, 4, and 5. Those are just visual numbers, not really meant to signify anything but the literal order of the list.
Hopefully that'll clear some things up.