This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:spring2015:data:projects:sln0 [2015/01/28 14:25] – [Submit Tool Usage] wedge | haas:spring2015:data:projects:sln0 [2015/01/29 00:19] (current) – wedge | ||
---|---|---|---|
Line 40: | Line 40: | ||
As such, if we were to have a solitary node containing a 17, and pointing at nothing (NULL), it could be drawn as follows: | As such, if we were to have a solitary node containing a 17, and pointing at nothing (NULL), it could be drawn as follows: | ||
- | **PICTURE OF NODE** | + | {{ : |
===names and nodes=== | ===names and nodes=== | ||
Line 52: | Line 52: | ||
So here is a picture of what that same node would look like, while also associating a variable known as **start** with it. | So here is a picture of what that same node would look like, while also associating a variable known as **start** with it. | ||
- | **PICTURE OF NAMED NODE** | + | {{ : |
===temporary node variables=== | ===temporary node variables=== | ||
Line 62: | Line 62: | ||
<code c> | <code c> | ||
tmp = start; | tmp = start; | ||
- | </code | + | </code> |
And that would produce the following result: | And that would produce the following result: | ||
- | **IMAGE of node with tmp and start** | + | {{ : |
Note that **tmp** does **NOT** point to **start**, which points to the node-- instead, **tmp** points to what **start** points to. This is very important. | Note that **tmp** does **NOT** point to **start**, which points to the node-- instead, **tmp** points to what **start** points to. This is very important. | ||
Line 80: | Line 80: | ||
That would leave us with the following image: | That would leave us with the following image: | ||
- | **IMAGE of updated node** | + | {{ : |
===connecting two nodes together=== | ===connecting two nodes together=== | ||
If we had a second node, **tmp2**, containing a 37 and pointing at nothing, we'd have a scenario like this: | If we had a second node, **tmp2**, containing a 37 and pointing at nothing, we'd have a scenario like this: | ||
- | **IMAGE of two nodes** | + | {{ : |
If we wanted start' | If we wanted start' | ||
Line 97: | Line 97: | ||
The result of that assignment results in the following: | The result of that assignment results in the following: | ||
- | **IMAGE of two connected nodes** | + | {{ : |
===connecting a new node, which becomes the start=== | ===connecting a new node, which becomes the start=== | ||
What if we were to add a third node to our scenario (containing a 48): | What if we were to add a third node to our scenario (containing a 48): | ||
- | **IMAGE of our nodes** | + | {{ : |
We have our existing two connected nodes, and our new node, currently identified by **tmp3**. | We have our existing two connected nodes, and our new node, currently identified by **tmp3**. | ||
Line 114: | Line 114: | ||
</ | </ | ||
- | **IMAGE of result** | + | {{ : |
BUT: the intention of having **start** is to always have it pointing at the FIRST node in our list. So, as a result of that assignment, we need to re-assign start. | BUT: the intention of having **start** is to always have it pointing at the FIRST node in our list. So, as a result of that assignment, we need to re-assign start. | ||
Line 126: | Line 126: | ||
That results in the following: | That results in the following: | ||
- | **IMAGE of list of 3 nodes** | + | {{ : |
Note that, at any point, the tmp/ | Note that, at any point, the tmp/ | ||
Line 134: | Line 134: | ||
</ | </ | ||
- | **IMAGE of 3 nodes** | + | {{ : |
If it hasn't become obvious yet, drawing pictures like this (especially in a step-by-step manner) will be invaluable in aiding you through both debugging and solving these various tasks you'll face this semester. | If it hasn't become obvious yet, drawing pictures like this (especially in a step-by-step manner) will be invaluable in aiding you through both debugging and solving these various tasks you'll face this semester. | ||
Line 151: | Line 151: | ||
The picture drawn should resemble: | The picture drawn should resemble: | ||
- | **IMAGE** | + | {{ : |
====Copying a node==== | ====Copying a node==== | ||
Line 164: | Line 164: | ||
Which would give us: | Which would give us: | ||
- | **IMAGE** | + | {{ : |
Note that assigning a variable to an existing node is NOT the same as copying. If we were to say: | Note that assigning a variable to an existing node is NOT the same as copying. If we were to say: | ||
Line 174: | Line 174: | ||
Does this create another copy? NO. It merely creates a scenario where two variables reference one node: | Does this create another copy? NO. It merely creates a scenario where two variables reference one node: | ||
- | **IMAGE** | + | {{ : |
====Removing a node==== | ====Removing a node==== | ||
Line 187: | Line 187: | ||
The result will be this: | The result will be this: | ||
- | **IMAGE** | + | {{ : |
We can run into interesting situations when we remove a node that has multiple variables pointing at it. For instance-- tmp and tmp3. If we were to say: | We can run into interesting situations when we remove a node that has multiple variables pointing at it. For instance-- tmp and tmp3. If we were to say: | ||
Line 197: | Line 197: | ||
We'd potentially end up with the following scenario: | We'd potentially end up with the following scenario: | ||
- | **IMAGE** | + | {{ : |
That's because when we de-allocate, | That's because when we de-allocate, |