CSC 161 Grinnell College Spring, 2015
 
Imperative Problem Solving and Data Structures
 
 

Module on Pointers, Stacks, and Queues

Summary and Main Topics

This module applies previous concepts (e.g., pointers, linked lists) to widely-used dynamic data structures. Topics covered include:

  1. More about pointers
  2. Variations of linked lists
  3. Stacks
  4. Queues
Day Topic Preparation In-class Due Date Availability
for
Extra
Credit
Friday, April 17 Abstract data types
Stacks, queues
Readings on      
Monday, April 20 Supplemental Problem 4   Supplemental Problem 4 (done individually) Monday, April 20  
Monday, April 20 Abstract data types
Stacks
reading on stacks lab on stacks    
Tuesday, April 21 Abstract data types
Queues — Array Implementation
reading on queues lab on queues (arrays) Due: Tuesday, April 28  
Wednesday, April 22 Hour Test 2 Covers through Lab on Stacks with Arrays and Lists    
Friday, April 24 Abstract data types
Queues — List Implementation
reading on queues lab on queues (lists) Due: Tuesday, April 28  
Monday, April 27 Bash scripts
Using Bash scripts for testing
reading on Bash Scripts lab on bash scripts   extra credit if submitted by Friday, May 8
Tuesday, April 28 Project Examples: Stack implementations
  • main program using stack operations according to some implementation
  • approach 1, in which the stack contains an array of pointers and the stack just points to strings as entered
  • approach 2, in which the stack contains an array of the strings themselves and strings are copied onto the stack and copied back; for purposes of illustration, each string on the stack is limited to 5 characters.
  • approach 3, in which the stack contains an array of pointers and space is allocated to copy the string during each push operation.
  • approach 4, in which the stack contains an array of the strings themselves and strings are copied onto the stack and just a reference is to the string is returned by a pop.
  • stack-storage-results.shtml, which tabulates the output when the main program is run with each of the four stack implementations.
Variations with Stacks Due: Friday, May 1  

Project: Variations with Stacks

The readings for this project show four different approaches for implementing a stack based on an underlying array structure. In particular, each approach uses a fixed size array to store strings on a stack. When all items in the array are in use, the stack is full and further push operations will fail.

The variations among the stack implementations involve what is actually stored during a push operation and what is returned during a pop operation. In brief, some possibilities are:

The main program in the reading pushes several items onto several stacks and then pops the stacks and prints the results. All four stack approaches work fine in this simple context.

Project, Part 1: Code Analysis

Examine each of the four implementation approaches supplied in the project reading. For each approach, identify:

In each case, briefly justify your conclusions.

Project, Part 2: Experimentation

The program stack-project.c creates a single stack myStack and then uses the standard stack operations in the following sequence:

stack-storage-results.shtml shows the results the instructor obtained when running stack-project.c with each of the four stack implementation approaches..

Project, Part 3: A Stack of Pictures

Suppose you wanted to use a stack to store successive pictures taken by a Scribbler 2 robot. For each of the four approaches identified for strings,

Project, Part 4: Your Preference for a Stack of Pictures

In reviewing various approaches for implementing an array-based stack of pictures, how would you proceed? Would you adapt one of the approaches discussed for strings? Would you use a different approach (explain)?

Grading