This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:fall2014:data:projects:dska0-solution [2014/10/31 22:30] – [Linked List Code Inversion] wedge | haas:fall2014:data:projects:dska0-solution [2014/10/31 22:38] (current) – [Linked List Code Inversion] wedge | ||
---|---|---|---|
Line 29: | Line 29: | ||
{{ : | {{ : | ||
- | Note that the NULL terminating the list is to the left of the list start... so again, an inversion or negation what we are used to seeing. | + | Note that the NULL terminating the list is to the left of the list start... so again, an inversion or negation |
- | The trick here is that we still view this list from left to right-- start is on the left (or beginning), and end is on the right (the contextual end). In this scenario, the connections work against the grain when using the list. | + | The trick here is that we still "view" |
=====Appending===== | =====Appending===== | ||
Line 58: | Line 58: | ||
* **insert()** in a next-oriented singly-linked list is functionally equivalent to **append()** in a previous-oriented singly-linked list | * **insert()** in a next-oriented singly-linked list is functionally equivalent to **append()** in a previous-oriented singly-linked list | ||
* **append()** in a next-oriented singly-linked list is functionally equivalent to **insert()** in a previous-oriented singly-linked list | * **append()** in a next-oriented singly-linked list is functionally equivalent to **insert()** in a previous-oriented singly-linked list | ||
- | * To display the list from start to end in a previous-oriented singly-linked list, we effectively need to perform | + | * To display the list from start to end in a previous-oriented singly-linked list, we effectively need to use the **displayb()** logic to assist us in our task. |
More precisely, to convert the next-oriented linked-list **insert()** into a previous-oriented linked-list **append()**: | More precisely, to convert the next-oriented linked-list **insert()** into a previous-oriented linked-list **append()**: | ||
Line 66: | Line 66: | ||
====positioning tmp==== | ====positioning tmp==== | ||
- | You'll see that, instead of seeking from the start of the list, we must seek from the end. And just as with next-insert(), | + | You'll see that, instead of seeking from the start of the list, we must seek from the end. And just as with next-insert(), |
The only difference here (if we were to implement **getpos()/ | The only difference here (if we were to implement **getpos()/ | ||
Line 82: | Line 82: | ||
</ | </ | ||
+ | Note the -1 and +1 difference. | ||
====navigating with while==== | ====navigating with while==== | ||
- | Obviously, since **getpos()/ | + | Obviously, since **getpos()/ |
Likely, something of the form: | Likely, something of the form: |