This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:summer2015:data:projects:dll0 [2015/06/21 14:34] – [Objective] wedge | haas:summer2015:data:projects:dll0 [2015/06/27 20:30] (current) – [list library] wedge | ||
---|---|---|---|
Line 15: | Line 15: | ||
=====Objective===== | =====Objective===== | ||
In this project, we continue our doubly-linked code re-write, this time focusing on the linked list. | In this project, we continue our doubly-linked code re-write, this time focusing on the linked list. | ||
- | =====Procedure to Obtain | + | =====Procedure to obtain |
- | As this is a rewrite, | + | As dll0 utilizes |
<cli> | <cli> | ||
- | lab46: | + | lab46: |
... | ... | ||
</ | </ | ||
- | The " | + | When you upgrade, your existing code is copied over, because the next project builds upon what you did previously. |
- | But when you " | + | Once you run " |
- | + | ||
- | Once you run " | + | |
=====Project Overview===== | =====Project Overview===== | ||
For this project, we're going to be re-implementing MOST of the previous node and list functions. There have been a few changes, namely: | For this project, we're going to be re-implementing MOST of the previous node and list functions. There have been a few changes, namely: | ||
- | ====In inc/ | ||
- | <code c 1> | ||
- | #ifndef _NODE_H | ||
- | #define _NODE_H | ||
- | |||
- | #include < | ||
- | |||
- | struct node { | ||
- | char | ||
- | struct node *after; | ||
- | struct node *prior; | ||
- | }; | ||
- | typedef struct node Node; | ||
- | |||
- | Node *mknode(char | ||
- | Node *cpnode(Node *); // duplicate node | ||
- | Node *rmnode(Node *); // deallocate node | ||
- | |||
- | #endif | ||
- | </ | ||
- | |||
- | There is an addition of a " | ||
- | |||
- | The node info element has been renamed to " | ||
====In inc/ | ====In inc/ | ||
Line 63: | Line 37: | ||
#define _LIST_H | #define _LIST_H | ||
- | #include " | + | #include " |
- | + | ||
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
struct list { | struct list { | ||
- | Node *first; | + | Node *first; |
- | Node *last; | + | Node *last; |
}; | }; | ||
- | typedef struct list List; // because we deserve nice things | ||
- | int mklist (List **); | + | code_t |
- | int cplist (List *, List **); // duplicate list contents | + | code_t |
- | int insert (List **, Node *, Node *); | + | code_t |
- | int append (List **, Node *, Node *); | + | code_t |
- | int display(List *, int); // display list from start to end | + | code_t |
- | int find (List *, int, Node **); // locate node containing | + | code_t |
#endif | #endif | ||
</ | </ | ||
- | The following changes have taken place: | + | The following changes have taken place from the singly-linked list implementation: |
* **qty** has been removed from the list | * **qty** has been removed from the list | ||
Line 98: | Line 63: | ||
* **displayf()/ | * **displayf()/ | ||
- | There is now a set of status/ | + | Just as with the doubly-linked node, there are now a set of status/ |
+ | ====In inc/ | ||
+ | In addition to what was there previously, we see the following: | ||
+ | |||
+ | <code c 1> | ||
+ | // Status codes for the doubly linked list implementation | ||
+ | // | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | </ | ||
+ | |||
+ | Similar in many ways to the doubly-linked node status codes, we see a new possibility: | ||
====list operation status codes==== | ====list operation status codes==== | ||
You'll notice the presence of a set of # | You'll notice the presence of a set of # | ||
Line 111: | Line 93: | ||
* **DLL_EMPTY** - result is an empty list (may or may not be in error) | * **DLL_EMPTY** - result is an empty list (may or may not be in error) | ||
* **DLL_DEFAULT_FAIL** - default state of unimplemented functions (default error) | * **DLL_DEFAULT_FAIL** - default state of unimplemented functions (default error) | ||
- | * **DLL_FAIL** - some error occurred | + | * **DLL_ERROR** - some error occurred |
+ | * **DLL_INVALID** - invalid use (passing a NULL pointer) | ||
For example, in the case of " | For example, in the case of " | ||
- | * DLL_FAIL | + | * DLL_ERROR |
* DLL_MALLOC_FAIL (a problem has occurred when using malloc()) | * DLL_MALLOC_FAIL (a problem has occurred when using malloc()) | ||
* DLL_NULL (no memory allocated, so list cannot be anything but NULL) | * DLL_NULL (no memory allocated, so list cannot be anything but NULL) | ||
Line 159: | Line 142: | ||
To assist you in verifying a correct implementation, | To assist you in verifying a correct implementation, | ||
- | ====node library==== | ||
- | Here is what you should get for node: | ||
- | |||
- | <cli> | ||
- | lab46: | ||
- | ==================================================== | ||
- | = Verifying Doubly-Linked Node Functionality | ||
- | ==================================================== | ||
- | [mknode] Total: | ||
- | [cpnode] Total: | ||
- | [rmnode] Total: | ||
- | ==================================================== | ||
- | | ||
- | ==================================================== | ||
- | lab46: | ||
- | </ | ||
====list library==== | ====list library==== | ||
Line 184: | Line 151: | ||
= Verifying Doubly-Linked List Functionality | = Verifying Doubly-Linked List Functionality | ||
==================================================== | ==================================================== | ||
- | [mklist] Total: | + | [mklist] Total: |
- | [cplist] Total: | + | [cplist] Total: |
- | [append] Total: | + | [append] Total: |
- | [insert] Total: | + | [insert] Total: |
| | ||
[find] Total: | [find] Total: | ||
==================================================== | ==================================================== | ||
- | | + | |
==================================================== | ==================================================== | ||
lab46: | lab46: |