User Tools

Site Tools


notes:data:fall2022:projects:dls0

BACKGROUND

Stacks are linear data structures, that may be structured by linked lists. Linked lists are only accessed by one end and in the case of our project, this may be the lead or last node, (we will have to verify that with the unit tests scripts).

In the dls0/inc directory is a new file, stack.h , which defines the stack struct. The members of the stack struct for this project include Node *top (a pointer to the top of the stack), List *data (pointer to stack data), ulli size (size of the stack).

cd

SPECIFICATIONS

The top of the stack follows the list in reverse order. The top of the stack will be equal to the last node of the list.

myStack → top = myList → last

There will be approximately 7 functions, will have to confirm that once you upgrade. These new functions go as follows:

  • push() - Place a new node onto top of stack.
  • pop() - Remove a node from top of stack.
  • peek() - See node from top of stack.
  • isempty() - Return if stack is empty or not.
  • cpstack() - Copy stack to another.
  • mkstack() - Create and initialize a new stack.
  • rmstack() - Empty, deallocate, and nullify stack.

Do your best to not reinvent the wheel. This project contains a lot of work with node's and list's and thoughtful use of previously made functions relating to those data structures will lead to cleaner code. This is also a time to test your previously made functions in an actual use environment, where you can see if it actually works outside of specified unit tests.

Applying List functions in stack functions

Below are pairings of stack functions on the left, and list functions that could be very useful in accomplishing these stack functions on the right.
mk.c → mklist
push.c → append
pop.c → obtain
cpstack.c → mkstack, cplist
peek.c → cpnode
rmstack.c → rmlist

USE YOUR LIST FUNCTIONS TO HANDLE NODES WITHIN THE STACKS

KEY NOTE: Remember that the dereferenced version of the double pointers inside other functions you use should be NULL. Most of the functions previously made should have had an error if the dereferenced list/node was not NULL.

*Our task is to ask questions on Discord or in class and document our findings on this wiki page collaboratively, regarding the functionality of this project.

*For anybody interested in editing the wiki page, here is the dokuwiki user guide: https://www.dokuwiki.org/wiki:syntax#basic_text_formatting -Ash

PROGRAM

Inside the stack are 3 different objects, a node, a list, and the size of the stack. The node is the top of the stack, and follows the last node of the list. For the purpose of your push and pop functions, new nodes from push should go to the end of the list, and that should be the new top. For pop, it should take off the end of the list, and reassign the new top, which is the last node in the list. Also, you can make use of the make command -make use-test-reference. This uses a working implementation of object files from the previous dllX projects, and can very much help you if your previous projects did not pass all unit tests.

OUTPUT SPECIFICATIONS

No output should be visible outside of testing purposes inside unit tests. Functions will modify the corresponding list/node/stack according to what is asked of the function.

UNIT TESTS

notes/data/fall2022/projects/dls0.txt · Last modified: 2022/11/11 01:30 by zswartwo