This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:fall2017:data:projects:sln0 [2017/08/27 15:35] – [Displaying the list] wedge | haas:fall2017:data:projects:sln0 [2017/08/29 12:44] (current) – [Objective] wedge | ||
---|---|---|---|
Line 16: | Line 16: | ||
In this project, we start conceptualizing aspects of the program we wrote in last week's project (with the arrays), and start looking at each unit of information as an arbitrary **node** unit, connected to its immediate proceeding neighbor via a **link**. | In this project, we start conceptualizing aspects of the program we wrote in last week's project (with the arrays), and start looking at each unit of information as an arbitrary **node** unit, connected to its immediate proceeding neighbor via a **link**. | ||
- | This gets us into a central theme of the course which we'll be running with from now until the end- the idea of a linked nodes, or in our current case: singly-linked nodes. | + | This gets us into a central theme of the course which we'll be running with from now until the end- the idea of linked nodes, or in our current case: singly-linked nodes. |
=====Overview===== | =====Overview===== | ||
Line 51: | Line 51: | ||
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. | ||
- | {{ :haas:fall2017: | + | {{ :haas:fall2016: |
===temporary node variables=== | ===temporary node variables=== | ||
Line 65: | Line 65: | ||
And that would produce the following result: | And that would produce the following result: | ||
- | {{ :haas:fall2017: | + | {{ :haas:fall2016: |
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 79: | Line 79: | ||
That would leave us with the following image: | That would leave us with the following image: | ||
- | {{ :haas:fall2017: | + | {{ :haas:fall2016: |
===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: | ||
- | {{ :haas:fall2017: | + | {{ :haas:fall2016: |
If we wanted start' | If we wanted start' | ||
Line 96: | Line 96: | ||
The result of that assignment results in the following: | The result of that assignment results in the following: | ||
- | {{ :haas:fall2017: | + | {{ :haas:fall2016: |
===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): | ||
- | {{ :haas:fall2017: | + | {{ :haas:fall2016: |
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 113: | Line 113: | ||
</ | </ | ||
- | {{ :haas:fall2017: | + | {{ :haas:fall2016: |
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 125: | Line 125: | ||
That results in the following: | That results in the following: | ||
- | {{ :haas:fall2017: | + | {{ :haas:fall2016: |
Note that, at any point, the tmp/ | Note that, at any point, the tmp/ | ||
Line 133: | Line 133: | ||
</ | </ | ||
- | {{ :haas:fall2017: | + | {{ :haas:fall2016: |
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 139: | Line 139: | ||
The longer you hold out and resist from drawing pictures, the longer a lot of this may be difficult or frustrating. | The longer you hold out and resist from drawing pictures, the longer a lot of this may be difficult or frustrating. | ||
====Creating a node==== | ====Creating a node==== | ||
- | To create a node, in pseudo-code, | + | To create a node, in pseudo-code, |
**mknode()** returns the location of this new node, so in order to prevent it from getting lost, we need to assign a variable to it (much as our start, tmp, tmp2, tmp3 variables do). | **mknode()** returns the location of this new node, so in order to prevent it from getting lost, we need to assign a variable to it (much as our start, tmp, tmp2, tmp3 variables do). |