This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
haas:fall2017:data:projects:sln0 [2016/08/20 16:11] – external edit 127.0.0.1 | 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 32: | Line 32: | ||
For starters, our " | For starters, our " | ||
- | * a data field called **info** | + | * a data field called **contents** |
- | * an arrow pointing to the next neighboring node to our immediate right, called **there** | + | * an arrow pointing to the next neighboring node to our immediate right, called **to** |
If we do not have another node to point an arrow at, we'll want to point it at a specific value indicating nothing. In our case, that value is **NULL** (must be all caps). | If we do not have another node to point an arrow at, we'll want to point it at a specific value indicating nothing. In our case, that value is **NULL** (must be all caps). | ||
- | As such, if we were to have a solitary node containing a 17, and its 'there' pointer pointing at nothing (NULL), it could be drawn as follows: | + | As such, if we were to have a solitary node containing a 17, and its 'to' pointer pointing at nothing (NULL), it could be drawn as follows: |
- | {{ :haas:fall2016: | + | {{ :haas:fall2017: |
===names and nodes=== | ===names and nodes=== | ||
Line 74: | Line 74: | ||
<code c> | <code c> | ||
- | tmp -> info = 57 | + | tmp -> contents |
</ | </ | ||
Line 89: | Line 89: | ||
<code c> | <code c> | ||
- | start -> there = tmp2 | + | start -> to = tmp2 |
</ | </ | ||
- | (as tmp was also pointing to the same node, we could just as easily have said "tmp -> there = tmp2", and we may have wanted to use that approach instead, as the idea behind **start** is to use it as an anchoring reference point only). | + | (as tmp was also pointing to the same node, we could just as easily have said "tmp -> to = tmp2", and we may have wanted to use that approach instead, as the idea behind **start** is to use it as an anchoring reference point only). |
The result of that assignment results in the following: | The result of that assignment results in the following: | ||
Line 110: | Line 110: | ||
<code c> | <code c> | ||
- | tmp3 -> there = start | + | tmp3 -> to = start |
</ | </ | ||
Line 137: | Line 137: | ||
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. | ||
+ | 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). | ||
Line 221: | Line 222: | ||
<code c> | <code c> | ||
start = tmp = mknode(2) | start = tmp = mknode(2) | ||
- | tmp -> there = mknode(4) | + | tmp -> to = mknode(4) |
- | tmp = tmp -> there | + | tmp = tmp -> to |
- | start -> there -> there = mknode(8) | + | start -> to -> to = mknode(8) |
- | tmp = tmp -> there | + | tmp = tmp -> to |
- | tmp -> there = mknode(16) | + | tmp -> to = mknode(16) |
</ | </ | ||
Line 237: | Line 238: | ||
====Displaying the list==== | ====Displaying the list==== | ||
- | Assuming you do not know the composition of the list, write the code to display the list contents from start to end (end is defined as when a node's 'there' pointer points to NULL) | + | Assuming you do not know the composition of the list, write the code to display the list contents from start to end (end is defined as when a node's 'to' pointer points to NULL) |
====Appending to the list==== | ====Appending to the list==== |