CS 241 Data Organization using C
Lab 10: More fun with lists and stacks!


November 8, 2018

The purpose of lab today is to start working on the ADT parts of Homework 8.

1 Before Class

We’re going to get started writing code to help with homework 8 today. If you’ve already written code for this, start there. Otherwise, create a new c file called linkedlist.c and download the associated header file linkedlist.h.

From last lab, we created a Makefile and wrote a few functions that were mostly written in lecture. Before starting on this lab, createNode and most of insertSorted need to be written. In addition, the recursive version of printList used for singly linked lists that we wrote during class can be reused here.

2 Getting Started

Today we’re going to focus on the stack method pushStack. This method will treat the list as a stack. It will insert data at the head of a list and return the updated head pointer.

3 To do during lab

Points will be allocated as follows

1
Existing code included and appropriate functions are recursive.
1
pushStack method started. There is appropriate testing code in either the main method of the linkedlist.c or an external code file studentlisttest.c. If unfinished, it’s clear that the student knows where to go from here.
1
pushStack method completed. There’s a comment that notes the worst case run time and how it compares to an optimal pushStack method.

4 More time?

Continue working on homework 8 and the associated testing code. Test your code with valgrind to make sure that your code doesn’t leak any memory. Think about the optimal run time of each method – how does the run times of your methods compare?

5 Turning in your program

It’s ok not to finish this assignment – get through as much as you can.

Zip up your linkedlist.c file (and perhaps also your studentlisttest.c file) into a zip file entitled yourCSUsername.zip. Then drop the zip file into the dropbox under the lab-10 folder.