User Tools

Site Tools


Sidebar

projects

haas:fall2014:data:projects:sll0

Corning Community College

CSCS2320 Data Structures

~~TOC~~

Project: SLL0

Errata

This section will document any updates applied to the project since original release:

  • revision 1: deployed unit test for displayf() (20141002)
  • revision 2: fixed a typo in the unit test for displayf(), deployed unit-setpos.c and unit-getpos.c (20141004)
  • revision 3: fixed a logic problem in src/list/cp.c (it was skipping the last node). Also:
    • deployed testing/list/unit/unit-mklist.c
    • deployed testing/list/unit/unit-cplist.c
    • fixed a typo in testing/list/unit/unit-displayf.c
    • with this update, all unit tests and content for project sll0 are available (20141004)
  • revision 4: testing/list/unit/unit-displayf.c was not updating list qty. FIXED.
    • a lot of people seem to be basing their displayf() off of qty… while this can work, it facilitates your desire to exert control over the problem. Let it flow. (20141008)

Objective

We've made it to lists! Time to start applying nodes to more elaborate manipulations, all while contained within our new (singly-linked) list implementation!

Reference

If you haven't done so yet, you absolutely, positively, MUST watch this video: http://www.youtube.com/watch?v=5VnDaHBi8dM

Procedure for bootstrapping

Obtain

On Lab46, change into your node1 directory (I'll use ~/src/data/node1/ in my examples):

lab46:~$ cd src
lab46:~/src$ cd data
lab46:~/src/data$ cd node1
lab46:~/src/data/node1$ 

NOTE: At this point you should be completed with the node1 project.

If you are done, and a make help shows an upgrade-sll0 option being available, we can proceed with bootstrapping the sll0 project:

lab46:~/src/data/node0$ make upgrade-sll0
Archiving the project ...
Compressing the archive ...
Setting Permissions ...
You may now switch to the ../sll0 directory
lab46:~/src/data/node1$ 

As you can see from the last line: You may now switch to the ../sll0 directory

So let's do it:

lab46:~/src/data/node1$ cd ../sll0
lab46:~/src/data/sll0$ 

Overview

Just as before, you'll see various files and directories located here (one regular file, Makefile, and 5 directories). The directory structure (note, not all these directories may yet be present, although a few more are here than were in the node0 project) for the project is as follows:

  • bin: compiled, executable programs will reside here
  • inc: project-related header files are here (NEW file: list.h)
  • lib: compiled, archived object files (aka libraries) will reside here
  • src: subdirectory tree containing our Data Structure implementations
    • node: location of our node implementation
    • list: location of our linked list implementation (NEW in this project)
    • stack: location of our stack implementation (manipulation of lists)
    • queue: location of our queue implementation (a different manipulation of lists)
  • testing: subdirectory tree containing our test apps and unit tests
    • node: node-related testing files will be here
      • app: end-user applications, demonstrating use
      • unit: unit tests, helping to verify correct implementation
    • list: list-related testing files (NEW in this project)
      • app: end-user applications, demonstrating use
      • unit: unit tests, helping to verify correct implementation

Operating

The project is driven by a fleet of optimized Makefiles, which will facilitate the compiling process for us.

Each Makefile plays a unique role (the closer the Makefile is to the source code, the more specialized it becomes).

The base-level Makefile is used to enact whole-project actions, such as initiating a compile, cleaning the project directory tree of compiled and object code, submitting projects, or applying bug-fixes or upgrading to other projects.

Running make help will give you a list of available options:

lab46:~/src/data/sll0$ make help

****************[ Data Structures List Implementation ]*****************
** make                     - build everything (libs and testing)     **
** make debug               - build everything with debug symbols     **
**                                                                    **
** make libs                - build all supporting libraries          **
** make libs-debug          - build all libraries with debug symbols  **
** make testing             - build unit tests                        **
** make testing-debug       - build unit tests with debugging symbols **
**                                                                    **
** make save                - create a backup archive                 **
** make submit              - submit assignment (based on dirname)    **
** make update              - check for and apply updates             **
**                                                                    **
** make clean               - clean; remove all objects/compiled code **
** make help                - this information                        **
************************************************************************
lab46:~/src/data/sll0$ 

In general, you will likely make the most frequent use of these options:

  1. make: just go and try to build everything
  2. make debug: build with debugging support
  3. make clean: clean out everything so we can do a full compile

Most of what you do will be some combination of those 3 options.

Project Submission

When you are done with the project and are ready to submit it, you simply run make submit:

lab46:~/src/data/sll0$ make submit
...

Bugfixes and Updates

Sometimes, a typo or other issue will be uncovered in the provided code you have. I will endeavor to release updates which will enable you to bring your code up-to-date with my copy.

When a new update is available, you will start seeing the following appear as you go about using make:

lab46:~/src/data/sll0$ make
*********************************************************
*** NEW UPDATE AVAILABLE: Type 'make update' to apply ***
*********************************************************
...
lab46:~/src/data/sll0$ 

When this occurs, you may want to perform a backup (and/or commit/push any changes to your repository)– certain files may be replaced, and you do not want to lose any modifications you have made:

lab46:~/src/data/sll0$ make save
Archiving the project ...
Compressing the archive ...
Setting Permissions ...
lab46:~/src/data/sll0$ 

Once you have done that, go ahead and apply the update (note this output is from the node0 project update, so you will not see the exact same output):

lab46:~/src/data/sll0$ make update
Update 1 COMMENCING
Update 1 CHANGE SUMMARY: Fixed base and other Makefile typos
    Please reference errata section on project page for more information
Update 1 COMPLETE
Updated from revision 0 to revision 1
lab46:~/src/data/sll0$ 

At this point your code is up to date (obviously the above output will reflect whatever the current revision is).

Project Overview

header file

In src/inc/, you will find a new file: list.h

Take a look inside, and ask any questions to get clarification:

1
#ifndef _LIST_H
#define _LIST_H
 
#include "node.h"                       // list relies on node to work
 
struct list {
    Node *start;                        // pointer to start of list
    Node *end;                          // pointer to end of list
    int   qty;                          // running tally of nodes in list
};
typedef struct list List;               // because we deserve nice things
 
List *mklist(void  );                   // create/allocate new list struct
List *cplist(List *);                   // copy (duplicate) list
List *rmlist(List *);                   // remove all nodes from list
 
List *insert (List *, Node *, Node *);  // add node before given node
List *append (List *, Node *, Node *);  // add node after given node
List *obtain (List *, Node **       );  // obtain/disconnect node from list
 
void  displayf(List *, int);            // display list from start to end
void  displayb(List *, int);            // display list in reverse order
 
int   getpos(List *, Node *);           // retrieve position from given node
Node *setpos(List *, int   );           // seek to indicated node in list
 
Node *searchlist(List *, int);          // locate node containing value
List *sortlist  (List *, int);          // sort list (according to mode)
 
List *swapnode(List *, Node *, Node *); // swap positions of given nodes in list
 
#endif

This is your API for the list library. In order to use the list library three things need to happen:

  • you must #include “list.h” (generally already done you in this project)
  • you must link against lib/liblist.a (the Makefiles take care of this for you)
  • you must call the functions providing the appropriate arguments and handling the return values

list library

In src/list/, you will find 6 C files:

  • append.c - which will house the list append function
  • cp.c - which will handle list duplication
  • displayf.c - which will display the contents of your list from start to end
  • insert.c - which will house the list insert function
  • mk.c - which will handle the creation of new lists
  • pos.c - helper functions to locate list node positions and indices

Some code has been provided. Others have not. One of your tasks is to fill in the gaps, and implement the functions that have been left blank.

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.

NOTE: None of these files denote an entire runnable program. These are merely standalone functions. The various programs under the testing/ directory will use these functions in addition to their application logic to create complete executable programs.

You will also notice there are function prototypes for these list library functions in the list.h header file, located in the inc/ subdirectory, which you'll notice all the related programs you'll be playing with in this project are #includeing.

List library unit tests

In testing/list/unit/, you will find 3 files (along with a Makefile):

  • unit-cplist.c - unit test for cplist() library function
  • unit-mklist.c - unit test for mklist() library function
  • unit-rmlist.c - unit test for rmlist() library function

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!

Building the code

You've made changes to a file in src/list/, and are ready to see your results. What do we do?

First, let's have a second terminal open and logged into lab46. Put it in the base directory of the node1 project:

lab46:~$ cd src/data/sll0
lab46:~/src/data/sll0$  

Keep your other terminal in the ~/src/data/sll0/src/list/ directory, so you can more effectively make changes.

cleaning things out

If you've already ran make to build everything a few times, you may want to clean things out and do a fresh compile (never hurts, and might actually fix some problems):

lab46:~/src/data/sll0$ make clean
...
lab46:~/src/data/sll0$ 

compile project

Next, compile the whole project

lab46:~/src/data/sll0$ make
...

Our binaries

Compiled executables go in the bin directory, so if we change into there and take a look around we see the various executables built (both new with this project as well as migrated code from previous projects).

lab46:~/src/data/sll0$ cd bin
lab46:~/src/data/sll0/bin$ ls
...
lab46:~/src/data/sll0/bin$ 

Run the program

To run list-unit-append, we'd do the following (specify a relative path to the executable):

lab46:~/src/data/node1/bin$ ./list-unit-append

The program will now run, and do whatever it was programmed to do.

Submission Criteria

To be successful in this project, the following criteria must be met:

  • Code must compile cleanly (no warnings or errors)
    • all requested functions must be implemented in the related library
  • Executed programs must display in a manner similar to provided output
  • Processing must be correct based on input given and output requested
  • Output must be correct (i.e. the list visualization) based on values input
  • Code must be nicely and consistently indented (you may use the indent tool)
  • Code must be commented
  • Track/version the source code in a repository
  • Submit a copy of your source code to me using the submit tool (make submit will do this) by the deadline.
haas/fall2014/data/projects/sll0.txt · Last modified: 2014/10/08 18:34 by wedge