This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:spring2015:data:projects:dlq0 [2015/04/17 12:38] – [Errata] wedge | haas:spring2015:data:projects:dlq0 [2015/04/29 18:48] (current) – [Errata] wedge | ||
---|---|---|---|
Line 11: | Line 11: | ||
This section will document any updates applied to the project since original release: | This section will document any updates applied to the project since original release: | ||
- | * __revision | + | * __revision |
+ | * lacking a leading ' | ||
+ | * also, a few erroneous mentions of " | ||
+ | * __revision 2__: typo in unit-purge (20150427) | ||
+ | * " | ||
+ | * __revision 3__: typo in unit-dequeue (20150429) | ||
+ | * unit-dequeue was dequeueing backwards (FIXED) | ||
=====Objective===== | =====Objective===== | ||
Line 60: | Line 67: | ||
* **purge**: a way to quickly empty out a queue (evacuate its contents-- note this is partially similar in nature to what our **rmqueue()** function will do; only we won't take it the extra step of de-allocating and NULLifying the queue pointer). | * **purge**: a way to quickly empty out a queue (evacuate its contents-- note this is partially similar in nature to what our **rmqueue()** function will do; only we won't take it the extra step of de-allocating and NULLifying the queue pointer). | ||
+ | * this will be similar in nature to the list's **empty()** function, which properly clears a list to an empty state; only, **purge()** is operating at the queue level. | ||
- | While we may be implementing these supplemental functions, it should be noted that not only are they in no way necessary for using a queue, they could be detrimental | + | While we may be implementing these supplemental functions, it should be noted that not only are they in no way necessary for using a queue, they could be detrimental, |
Their inclusion should ONLY be viewed as a means of convenience (in certain scenarios they may result in less code needing to be written), but NOT as something you should routinely make use of. | Their inclusion should ONLY be viewed as a means of convenience (in certain scenarios they may result in less code needing to be written), but NOT as something you should routinely make use of. | ||
Line 81: | Line 89: | ||
For this project, we're going to be implementing the queue data structure atop of our recently re-implemented linked list (the doubly linked list). | For this project, we're going to be implementing the queue data structure atop of our recently re-implemented linked list (the doubly linked list). | ||
+ | |||
+ | ====In inc/ | ||
+ | Building on the **data.h** header file introduced in dls0, a section of status codes has been added for queues: | ||
+ | |||
+ | <code c> | ||
+ | // Status codes for the queue implementation | ||
+ | // | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | </ | ||
+ | |||
+ | You may notice that they equate to the same numerical values as the stack; that is because, for the purposes of our stack and queue implementations, | ||
====In inc/ | ====In inc/ | ||
Line 88: | Line 114: | ||
#define _QUEUE_H | #define _QUEUE_H | ||
- | #include " | + | #include " |
- | | + | #include " |
+ | // (which relies on node) | ||
struct queue { | struct queue { | ||
- | List *data; | + | List *data; |
- | Node *front; | + | Node *front; |
- | Node *back; | + | Node *back; |
- | | + | |
}; | }; | ||
- | typedef struct queue Queue; | + | typedef struct queue Queue; |
- | Queue *mkqueue(int | + | code_t |
- | Queue *cpqueue(Queue * ); // create a copy of an existing queue | + | code_t |
- | Queue *rmqueue(Queue * ); // clear and de-allocate | + | code_t |
- | Queue *purge(Queue * ); // empty a given queue | + | code_t |
- | int | + | code_t |
- | int | + | code_t |
#endif | #endif | ||
Line 117: | Line 144: | ||
In object-oriented programming, | In object-oriented programming, | ||
- | ====list library==== | ||
- | One more enhancement is in store for our venerable **display()** function, and that is described below: | ||
- | |||
- | ===display() enhancements=== | ||
- | You are also to implement an additional feature (resulting in 8 additional modes) to the **display()** function. | ||
- | |||
- | This means you'll need to expand the current modulus divide by 8 to one of 16. | ||
- | |||
- | The current modes are as follows: | ||
- | |||
- | <code c> | ||
- | // | ||
- | // 1 display the list forward, with positional values | ||
- | // 2 display the list backwards, no positional values | ||
- | // 3 display the list backwards, with positional values | ||
- | // 4 display the list forward, no positional values, in ASCII | ||
- | // 5 display the list forward, with positional values, in ASCII | ||
- | // 6 display the list backwards, no positional values, in ASCII | ||
- | // 7 display the list backwards, with positional values, in ASCII | ||
- | </ | ||
- | |||
- | The new feature is to toggle the display of the individual arrows (and the terminating NULL value) and much of the natural spacing we've used so far. It should also ditch, when in ASCII mode, the quotes we have been placing around the ASCII characters. | ||
- | |||
- | The idea here is, when combined with the ASCII representation of the list, **display()** can become a pretty useful function for displaying strings, which could come in handy. | ||
- | |||
- | Also, when dealing with numeric values, we could make use of this in applications where we are handling the construction of a numeric value (such as a bignum). | ||
- | |||
- | For positioned displays, this would seem to have less utility, but by having a space displayed before the position value, we can salvage the output nicely. | ||
- | |||
- | So for each of the above 8 modes, you'll have a WITH_ARROWS mode, and then a WITHOUT_ARROWS mode (leaving us with a total of 16 possible combinations). | ||
- | |||
- | For sane implementation purposes, for our current 8 (so modes 0-7), those will be considered to be WITH_ARROWS... whereas the remaining 8 combinations (8-15) will be WITHOUT_ARROWS. All other mode features will map in place (if you recognize the binary pattern I've been following you'll hopefully see how trivial this change (and the previous one) will be). | ||
- | |||
- | Also, when not displaying arrows, no NULL values will be displayed at all; this means that in the event we are running **display()** on a NULL or empty list, nothing but a newline should be displayed. | ||
- | |||
- | ==display() output examples based on mode== | ||
- | Let's say we have a list with the following elements: | ||
- | |||
- | start -> 51 -> 49 -> 51 -> 51 -> 55 -> NULL | ||
- | |||
- | ==mode " | ||
- | <cli> | ||
- | 5149515155 | ||
- | </ | ||
- | |||
- | ==mode " | ||
- | <cli> | ||
- | [0]51 [1]49 [2]51 [3]51 [4]55 | ||
- | </ | ||
- | |||
- | ==mode " | ||
- | <cli> | ||
- | 31337 | ||
- | </ | ||
- | |||
- | ==mode " | ||
- | <cli> | ||
- | [0]3 [1]1 [2]3 [3]3 [4]7 | ||
- | </ | ||
====queue library==== | ====queue library==== | ||
Line 229: | Line 197: | ||
lab46: | lab46: | ||
</ | </ | ||
- | ====List Library unit tests==== | ||
- | As a result of the required changes to **display()**, | ||
- | Be sure to run the various list unit tests and verification scripts to see which functions have fallen out of compliance with the list struct specification changes issued in this project. The **verify-list.sh** script can be especially useful in getting a big picture view of what work is needed. | ||
====Queue library unit tests==== | ====Queue library unit tests==== | ||
In **testing/ | In **testing/ | ||
Line 261: | Line 226: | ||
=====Expected Results===== | =====Expected Results===== | ||
- | To assist you in verifying a correct implementation, | + | To assist you in verifying a correct implementation, |
- | + | ||
- | + | ||
- | ====list library==== | + | |
- | Here is what you should get for list: | + | |
- | + | ||
- | < | + | |
- | lab46: | + | |
- | ==================================================== | + | |
- | = Verifying Doubly-Linked List Functionality | + | |
- | ==================================================== | + | |
- | [mklist] Total: | + | |
- | [cplist] Total: | + | |
- | [rmlist] Total: | + | |
- | [append] Total: | + | |
- | [insert] Total: | + | |
- | [obtain] Total: | + | |
- | | + | |
- | [findnode] Total: | + | |
- | [sortlist] Total: | + | |
- | [swapnode] Total: | + | |
- | ==================================================== | + | |
- | | + | |
- | ==================================================== | + | |
- | lab46: | + | |
- | </ | + | |
- | With the added feature to **display()**, | ||
- | But aside from this change to **display()**, | ||
====queue library==== | ====queue library==== | ||
Line 297: | Line 235: | ||
<cli> | <cli> | ||
lab46: | lab46: | ||
- | =================================================== | + | coming soon... |
- | = | + | |
- | =================================================== | + | |
- | [mkqueue] Total: | + | |
- | [cpqueue] Total: | + | |
- | [rmqueue] Total: | + | |
- | [purge] Total: | + | |
- | [enqueue] Total: | + | |
- | [dequeue] Total: | + | |
- | =================================================== | + | |
- | [RESULTS] Total: | + | |
- | =================================================== | + | |
lab46: | lab46: | ||
</ | </ |