Corning Community College
CSCS2320 Data Structures
~~TOC~~
======Project: DLL0======
=====Errata=====
This section will document any updates applied to the project since original release:
* __revision #__: (DATESTAMP)
=====Objective=====
In this project, we continue our doubly-linked code re-write, this time focusing on the linked list.
=====Procedure to obtain dll0=====
As dll0 utilizes the code generated in dln0, transitioning to this project is merely a matter of upgrading:
lab46:~/src/data/dln0$ make upgrade-dll0
...
When you upgrade, your existing code is copied over, because the next project builds upon what you did previously.
Once you run "**make upgrade-dll0**" you should have a **dll0** directory that you can access and commence working on just as you have with the other project directories.
=====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:
====In inc/list.h====
#ifndef _LIST_H
#define _LIST_H
#include "node.h" // list relies on node to work
struct list {
Node *initial; // pointer to start of list
Node *closing; // pointer to end of list
};
code_t mklist (List **); // create new list struct
code_t cplist (List *, List **); // duplicate list contents
code_t insert (List **, Node *, Node *); // add node before given node
code_t append (List **, Node *, Node *); // add node after given node
code_t display(List *, int); // display list start to end
code_t find (List *, char, Node **); // locate node with value
#endif
The following changes have taken place from the singly-linked list implementation:
* **qty** has been removed from the list (NO COUNTING!)
* **getpos()**/**setpos()** are no longer present. In many ways their functionality is no longer needed with the doubly-linked nature of the list (DO NOT RECREATE THEM!)
* **searchlist()** has been renamed to **find()** (aesthetic change, to keep function names at 8 characters or less, and now supports resuming (finding additional matches).
* **displayf()/displayb()** are gone, and previous functionality will be merged into one universal **display()** function.
Just as with the doubly-linked node, there are now a set of status/error codes that will be utilized as list function return values, so we can better report particular failures.
====In inc/data.h====
In addition to what was there previously, we see the following:
//////////////////////////////////////////////////////////////////////
//
// Status codes for the doubly linked list implementation
//
#define DLL_SUCCESS 0x0000000000010000
#define DLL_MALLOC_FAIL 0x0000000000020000
#define DLL_ALREADY_ALLOC 0x0000000000040000
#define DLL_NULL 0x0000000000080000
#define DLL_ERROR 0x0000000000100000
#define DLL_EMPTY 0x0000000000200000
#define DLL_INVALID 0x0000000000400000
#define DLL_DEFAULT_FAIL 0x0000000000800000
//////////////////////////////////////////////////////////////////////
//
// Options for list display() and support catlist() functions
//
#define DISPLAY_FORWARD 000
#define DISPLAY_NOPOSVALS 000
#define DISPLAY_POSVALS 001
#define DISPLAY_BACKWARD 002
Similar in many ways to the doubly-linked node status codes, we see a new possibility: EMPTY. This is the state of a list existing but having no nodes associated with it (which you should already be familiar with). Whenever this state exists, that status code MUST be set in the respective function being called (i.e. the list as a result of the function processing leaves us with an empty list).
====list operation status codes====
You'll notice the presence of a set of #define's in the list header file. These are intended to be used to report on various states of list status after performing various operations.
They are not exclusive- in some cases, multiple states can be applied. The intent is that you will OR together all pertinent states and return that from the function.
* **DLL_SUCCESS** - everything went according to plan, no errors encountered, average case
* **DLL_MALLOC_FAIL** - memory allocation failed (considered in error)
* **DLL_ALREADY_ALLOC** - memory has already been allocated (considered in error)
* **DLL_NULL** - result is NULL (probably 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_ERROR** - some error occurred
* **DLL_INVALID** - invalid use (passing a NULL pointer)
For example, in the case of "DLL_MALLOC_FAIL", there are actually a total of three states raised:
* DLL_ERROR (a problem has occurred)
* DLL_MALLOC_FAIL (a problem has occurred when using malloc())
* DLL_NULL (no memory allocated, so list cannot be anything but NULL)
ALL THREE states must be returned from the function in question should such an occurrence take place.
====list library====
In **src/list/**, you will find skeletons of the above prototyped functions, hollowed out in anticipation of being made operational.
Figure out what is going on, the connections, and make sure you understand it.
Be sure to focus on implementing the functionality from scratch (the more you do this from scratch, vs. referencing old code, the more it will help you).
====List library unit tests====
In **unit/list/**, you will find these new files:
* **unit-mklist.c** - unit test for **mklist()** library function
* **unit-cplist.c** - unit test for **cplist()** library function
* **unit-append.c** - unit test for **append()** library function
* **unit-insert.c** - unit test for **insert()** library function
* **unit-find.c** - unit test for **find()** library function
* **unit-display.c** - unit test for **display()** library function
Enhancements to these unit tests may be provided via dll0 project updates.
There are also corresponding **verify-FUNCTION.sh** scripts that will output a "MATCH"/"MISMATCH" to confirm overall conformance with the pertinent list functionality.
These are complete runnable programs (when compiled, and linked against the list library, which is all handled for you by the **Makefile** system in place).
Of particular importance, I want you to take a close look at:
* the source code to each of these unit tests
* the purpose of these programs is to validate the correct functionality of the respective library functions
* follow the logic
* make sure you understand what is going on
* ask questions to get clarification!
* the output from these programs once compiled and ran
* analyze the output
* make sure you understand what is going on
* ask questions to get clarification!
=====Expected Results=====
To assist you in verifying a correct implementation, a fully working implementation of the node and list libraries should resemble the following (when running the respective verify script):
====list library====
Here is what you should get for list:
lab46:~/src/data/dll0$ bin/verify-list.sh
======================================================
= Verifying Doubly-Linked List Functionality =
======================================================
[mklist] Total: 12, Matches: 12, Mismatches: 0
[cplist] Total: 18, Matches: 18, Mismatches: 0
[append] Total: 36, Matches: 36, Mismatches: 0
[insert] Total: 36, Matches: 36, Mismatches: 0
[display] Total: 12, Matches: 12, Mismatches: 0
[find] Total: 28, Matches: 28, Mismatches: 0
======================================================
[RESULTS] Total: 142, Matches: 142, Mismatches: 0
======================================================
lab46:~/src/data/dll0$
=====Submission=====
{{page>haas:fall2016:common:submitblurb#DATA&noheader&nofooter}}