Table of Contents

Corning Community College

CSCS2320 Data Structures

Project: DLQ0

Errata

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

Objective

In this project, resume our conceptual journey and explore another data structure: queues.

Background

A queue is considered one of the most important data structures, along with stack (last week's project), trees, and hash tables. And it is largely because of how often we find them playing out in nature or in our day-to-day lives.

The word “queue” is defined as:

Lists and Nodes

So, how does all this list and node stuff play into our queue implementation?

Well, like stacks, we're going to build the queue ON TOP OF lists (which are composed of nodes).

Therefore, a queue is a data structure that stores its data in a list (which consists of nodes), and we apply various rules/restrictions on our access of that list data.

The concept of restricting access is a very important one- which we did with our list as well (limiting our access to the list through the use of append(), insert(), and obtain() versus manipulating the there/back pointers manually all the time). By limiting how we access the data, we give ourselves certain algorithmic advantages:

conceptualizing a queue

It is common to think of a queue as a horizontal object, much like a line of people that need to be services (such as a checkout line at the grocery store, or a line at the bank).

Although we've commonly viewed lists horizontally (from left to right), there is absolutely nothing requiring this positional orientation.

Similarly, queues possess no mandatory orientation, but we do usually visualize them as horizontal entities, largely because that's how we commonly find ourselves entangled in this data structure in nature.

the queue

The queue data structure presents certain advantages that encourages its use in solving problems (why is the notion of forming lines important? What problems does that solve? How are resources more efficiently utilized by this act?), and we accomplish that by its compositional definition:

These qualities cause the queue to be described as a FIFO (or LILO) structure:

And that describes what is conceptually going on– if we can ONLY put our data on at one end (the back), and grab our data from the other (the front), the data most immediately available to us is that which we placed there first (hence the first one we enqueued would be the first one we get back when we dequeue it).

This concept is very important, and being aware of it can be of significant strategic importance when going about solving problems (and seeing its pattern proliferate in nature).

With that said, the existence of front, back, along with the core enqueue() and dequeue() functions defines the minimal necessary requirements to interface with a queue. Sometimes we'll see additional actions sneak in. While these may be commonly associated with queue, they should not be confused as core requirements of a queue:

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, as one could rely on them as a crutch.

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.

buffer size can matter

With a queue, there sometimes exists a need to cap its total size (especially in applications on the computer, we may have only allocated a fixed amount of space and cannot exceed it). For this reason, we will need to maintain a count of nodes in the queue (ie the underlying list). For this reason, we continue to make use of the list's qty element.

Additionally, the queue will have a configured maximum buffer- if the quantity of nodes in the list exceeds the configured buffer of the queue, we should prevent any additional enqueues.

It should also be pointed out that in other applications, a queue need not have a maximum buffer size.. in which case it can theoretically grow an indefinite amount. We will explore both conditions (unbounded and bounded) in this project.

queue error conditions

There are two very important operational error conditions a queue can experience:

Project Overview

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/data.h

Building on the data.h header file introduced in dls0, a section of status codes has been added for queues:

//////////////////////////////////////////////////////////////////////
//
// Status codes for the doubly linked queue implementation
//
#define  DLQ_SUCCESS         0x0000000100000000
#define  DLQ_CREATE_FAIL     0x0000000200000000
#define  DLQ_NULL            0x0000000400000000
#define  DLQ_EMPTY           0x0000000800000000        
#define  DLQ_OVERRUN         0x0000001000000000        
#define  DLQ_UNDERRUN        0x0000002000000000        
#define  DLQ_ERROR           0x0000004000000000
#define  DLQ_INVALID         0x0000008000000000
#define  DLQ_DEFAULT_FAIL    0x0000000000808000

In inc/queue.h

1
#ifndef _QUEUE_H
#define _QUEUE_H
 
//////////////////////////////////////////////////////////////////////
//
// Queue relies on list (which relies on node) to work.
//
#include "list.h"
 
//////////////////////////////////////////////////////////////////////
//
// Define the queue struct
//
struct queue {
    Node *front;                       // pointer to front of queue
    Node *back;                        // pointer to back of queue
    List *data;                        // pointer to queue data
    ulli  buffer;                      // queue length (0- unbounded)
};
 
code_t    mkqueue(Queue **, ulli    ); // create new queue (of length)
code_t    cpqueue(Queue  *, Queue **); // create a copy of a queue
code_t    rmqueue(Queue **          ); // de-allocate a queue
 
code_t    purge  (Queue **          ); // clear an existing queue
 
code_t    enqueue(Queue **, Node  * ); // add node to back of queue
code_t    dequeue(Queue **, Node ** ); // grab node at front of queue
 
#endif

For our queue implementation, we will continue to utilize the double pointer, in order to practice passing parameters by address.

This is necessary so that we can free up the return value of enqueue() and dequeue() to be used for status codes (ie look out for buffer overruns and underruns).

Also, while nothing is stopping you from doing so, the idea here is that things like buffer and the underlying list qty in queue transactions will NOT be accessed outside of the enqueue() and dequeue() functions. Just like my warnings about using qty in your list solutions (save for display() when showing position values in a backwards orientation)– do not consider buffer as a variable for your general use.

In object-oriented programming, both buffer and qty would be private member variables of their respective classes, unable to be used by anything other than their respective member functions.

queue library

In src/queue/, 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.

Again, your queue is to utilize the list for its underlying data storage operations. This is what the queue's data list pointer is to be used for.

Queue library unit tests

In unit/queue/, you will find these files:

There are also corresponding verify-FUNCTION.sh scripts that will output a “MATCH”/“MISMATCH” to confirm overall conformance with the pertinent queue functionality.

These are complete runnable programs (when compiled, and linked against the queue 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:

Expected Results

To assist you in verifying a correct implementation, a fully working implementation of the queue library should resemble the following (when running the respective verify script):

queue library

Here is what you should get for queue:

lab46:~/src/data/dlq0$ make check
======================================================
=    Verifying Doubly-Linked Queue Functionality     =
======================================================
   [mkqueue] Total:   6, Matches:   6, Mismatches:   0
   [enqueue] Total:  18, Matches:  18, Mismatches:   0
   [dequeue] Total:  19, Matches:  19, Mismatches:   0
   [cpqueue] Total:  17, Matches:  17, Mismatches:   0
     [purge] Total:   7, Matches:   7, Mismatches:   0
   [rmqueue] Total:  10, Matches:  10, Mismatches:   0
======================================================
   [RESULTS] Total:  77, Matches:  77, Mismatches:   0
======================================================
lab46:~/src/data/dlq0$ 

Submission

Project Submission

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

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

Submission Criteria

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

  • Project must be submit on time, by the posted deadline.
    • Early submissions will earn 1 bonus point per full day in advance of the deadline.
      • Bonus eligibility requires an honest attempt at performing the project (no blank efforts accepted)
    • Late submissions will lose 33% credit per day, with the submission window closing on the 3rd day following the deadline.
      • To clarify: if a project is due on Wednesday (before its end), it would then be 33% off on Thursday, 66% off on Friday, and worth 0% once it becomes Saturday.
      • Certain projects may not have a late grace period, and the due date is the absolute end of things.
  • all requested functions must be implemented in the related library
  • all requested functionality must conform to stated requirements (either on this project page or in comment banner in source code files themselves).
  • Output generated must conform to any provided requirements and specifications (be it in writing or sample output)
    • output obviously must also be correct based on input.
  • Processing must be correct based on input given and output requested
  • Project header files are NOT to be altered. During evaluation the stock header files will be copied in, which could lead to compile-time problems.
  • Code must compile cleanly.
    • Each source file must compile cleanly (worth 3 total points):
      • 3/3: no compiler warnings, notes or errors.
      • 2/3: one of warning or note present during compile
      • 1/3: two of warning or note present during compile
      • 0/3: compiler errors present (code doesn't compile)
  • Code must be nicely and consistently indented (you may use the indent tool)
    • You are free to use your own coding style, but you must be consistent
    • Avoid unnecessary blank lines (some are good for readability, but do not go overboard- double-spacing your code will get points deducted).
    • Indentation will be rated on the following scale (worth 3 total points):
      • 3/3: Aesthetically pleasing, pristine indentation, easy to read, organized
      • 2/3: Mostly consistent indentation, but some distractions (superfluous or lacking blank lines, or some sort of “busy” ness to the code)
      • 1/3: Some indentation issues, difficult to read
      • 0/3: Lack of consistent indentation (didn't appear to try)
  • Unless fundamentally required, none of your code should perform any inventory or manual counting. Basing your algorithms off such fixed numbers complicates things, and is demonstrative of a more controlling nature.
  • Code must be commented
    • Any “to be implemented” comments MUST be removed
      • these “to be implemented” comments, if still present at evaluation time, will result in points being deducted.
    • Commenting will be rated on the following scale (worth 3 total points):
      • 3/3: Aesthetically pleasing (comments aligned or generally not distracting), easy to read, organized
      • 2/3: Mostly consistent, some distractions or gaps in comments (not explaining important things)
      • 1/3: Light commenting effort, not much time or energy appears to have been put in.
      • 0/3: No original comments
      • should I deserve nice things, my terminal is usually 90 characters wide. So if you'd like to format your code not to exceed 90 character wide terminals (and avoid line wrapping comments), at least as reasonably as possible, those are two sure-fire ways of making a good impression on me with respect to code presentation and comments.
    • Sufficient comments explaining the point of provided logic MUST be present
  • Code must be appropriately modified
    • Appropriate modifications will be rated on the following scale (worth 3 total points):
      • 3/3: Complete attention to detail, original-looking implementation- also is not unnecessarily reinventing existing functionality
      • 2/3: Lacking some details (like variable initializations), but otherwise complete (still conforms, or conforms mostly to specifications), and reinvents some wheels
      • 1/3: Incomplete implementation (typically lacking some obvious details/does not conform to specifications)
      • 0/3: Incomplete implementation to the point of non-functionality (or was not started at all)
    • Implementation must be accurate with respect to the spirit/purpose of the project (if the focus is on exploring a certain algorithm to produce results, but you avoid the algorithm yet still produce the same results– that's what I'm talking about here).. worth 3 total points:
      • 3/3: Implementation is in line with spirit of project
      • 2/3: Some avoidance/shortcuts taken (note this does not mean optimization– you can optimize all you want, so long as it doesn't violate the spirit of the project).
      • 1/3: Generally avoiding the spirit of the project (new, different things, resorting to old and familiar, despite it being against the directions)
      • 0/3: entirely avoiding.
    • Error checking must be adequately and appropriately performed, according to the following scale (worth 3 total points):
      • 3/3: Full and proper error checking performed for all reasonable cases, including queries for external resources and data.
      • 2/3: Enough error checking performed to pass basic project requirements and work for most operational cases.
      • 1/3: Minimal error checking, code is fragile (code may not work in full accordance with project requirements)
      • 0/3: No error checking (code likely does not work in accordance with project requirements)
  • Any and all non-void functions written must have exactly 1 return statement
    • points will be lost for solutions containing multiple return statements in a function.
  • Absolutely, positively NO (as in ZERO) use of goto statements.
    • points will most definitely be lest for solutions employing such things.
  • No custom global variables! The header files provide all you need.
    • Do NOT edit the header files.
  • Track/version the source code in a repository
  • Filling out any submit-time questionnaires
  • Submit a copy of your source code to me using the submit tool (make submit will do this) by the deadline.