This is an old revision of the document!
Corning Community College
CSCS2320 Data Structures
~~TOC~~
This section will document any updates applied to the project since original release:
In this project, we take a step up from our singly linked list implementation- just as the singly-linked list was a step up from the individual nodes as an organizing unit for nodes.
So what does this give us? An organizing unit for lists! I'm calling them “ListGroups” or “GroupOfLists”, and we'll also sneak in true linked list functionality, by adding an “after” pointer to the List struct.
For this project, we need to make a couple modifications to the list struct (which you can also check out in inc/list.h):
struct list { Node *first; // pointer to start of list Node *last; // pointer to end of list struct list *after; // pointer to the next list unsigned long int qty; // number of nodes in list }; typedef struct list List; // because we deserve nice things
Specifically, we have an after pointer, so that we can point to an entirely separate list, along with a newly added qty variable, which will keep track of the number of nodes in the list.
To implement qty, all list functions that perform manipulations to the list will need to see some updating (insert(), append(), obtain(), and mklist()).
mklist() should also set the list's after pointer to a sane initial state (NULL).
With the updated list struct (and supporting list functions), we can now organize our lists with this new groupoflists struct (typedef'ed to Group for typing convenience).
#ifndef _GROUP_H #define _GROUP_H #include "list.h" // list relies on node to work struct groupoflists { List *first; // pointer to first list List *last; // pointer to last list }; typedef struct groupoflists Group; // because we deserve nice things Group *mkgroup(void); // create/allocate new Group Group *rmgroup(Group *); // clear/deallocate Group Group *linsert(Group *, List *, List *); // add list before given list Group *lappend(Group *, List *, List *); // add list after given list Group *lobtain(Group *, List **); // obtain/disconnect list from group long int ldisplay(Group *, long int); // display entire/aspects of list group long int lgetpos(Group *, List *); // retrieve position from given node List *lsetpos(Group *, long int); // seek to indicated node in list #endif
You should notice a striking similarity to the core list functionality (a first and a last pointer– only to Lists, and not Nodes), and the presence of Group manipulation and utility functions (appending, inserting, obtaining, displaying, getting/setting position, creating, and removing a group).
This project will test the level of your abstraction skills– for there isn't that much of a conceptual difference between the list functions and the group functions. The more you understand that, the easier this project will be.
In src/list/, you will find 5 new C files:
Take a look at the code there. These are the files that contain functions which will be compiled and archived into the node library (liblist.a) we will be using in this and future projects.
Figure out what is going on, make sure you understand it.
In testing/list/unit/, you will find these new files:
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:
Now that we've completed our list functionality, we can use these individual functions to piece together solutions to various everyday problems where a list could be effective. After all, that's a big aspect to learning data structures- they open doors to new algorithms and problem solving capabilities.
Our first endeavor will be that of palindromes (ie words/phrases that, when reversed, spell the same thing).
This implementation will be considered an extra credit opportunity, so as to offer those who have fallen behind (but working to get caught up) a reprieve on some of the credit they've lost.
It is also highly recommended to undertake as it will give you further experience working with these concepts.
To assist you in verifying a correct implementation, a fully working implementation of the node library and list library (up to this point) should resemble the following:
Here is what you should get for the node library:
lab46:~/src/data/sll2$ bin/verify-node.sh ==================================================== = Verifying Singly-Linked Node Functionality = ==================================================== [mknode] Total: 4, Matches: 4, Mismatches: 0 [cpnode] Total: 5, Matches: 5, Mismatches: 0 [rmnode] Total: 2, Matches: 2, Mismatches: 0 ==================================================== [RESULTS] Total: 11, Matches: 11, Mismatches: 0 ==================================================== lab46:~/src/data/sll2$
Here is what you should get for all the functions completed so far in the list library (sll0+sll1+sll2):
lab46:~/src/data/sll2$ bin/verify-list.sh ====================================================== = Verifying Singly-Linked List Functionality = ====================================================== [mklist] Total: 5, Matches: 5, Mismatches: 0 [insert] Total: 11, Matches: 11, Mismatches: 0 [displayf] Total: 4, Matches: 4, Mismatches: 0 [getpos] Total: 8, Matches: 8, Mismatches: 0 [setpos] Total: 9, Matches: 9, Mismatches: 0 [append] Total: 11, Matches: 11, Mismatches: 0 [searchlist] Total: 11, Matches: 11, Mismatches: 0 [cplist] Total: 11, Matches: 11, Mismatches: 0 [displayb] Total: 6, Matches: 6, Mismatches: 0 [compare] Total: 9, Matches: 9, Mismatches: 0 [obtain] Total: 28, Matches: 28, Mismatches: 0 [clearlist] Total: 3, Matches: 3, Mismatches: 0 [rmlist] Total: 3, Matches: 3, Mismatches: 0 [swapnode] Total: 9, Matches: 9, Mismatches: 0 [sortlist] Total: 27, Matches: 27, Mismatches: 0 ====================================================== [RESULTS] Total: 155, Matches: 155, Mismatches: 0 ====================================================== lab46:~/src/data/sll2$
To be successful in this project, the following criteria must be met: