CS 112 - Lab 7

Section 1: Introduction

The goal of this lab is to:

If you have not already done so, create a directory for this lab and copy the lab 7 files into it. If you start off in your home directory you can do the following:

	mkdir ~/cs112/lab7 
	cd ~/cs112/lab7 
	cp ~cs112/lab7/* .

Section 2: Topics for Lecture

Section 3: Description of Assignment

You are to implement a program that creates three contiguous arrays of size MAXSIZE containing random integers. Each array will be sorted using one of these three different sorting routines.

  • quicksort (using the UNIX function qsort( ))
  • insertion sort (using modified code from the textbook)
  • selection sort (using modified code from the textbook)

    You will time (using the function timer( ) from Lab 3) each sorting routine and display the results at the end of the program.

    You will be provided the following files:

  • main.c
  • sort.h (containing all prototypes, typedefs, and #defines)
  • timer.c

    Section 4: Hints

    For detailed information on the UNIX utility qsort, type man qsort at the UNIX prompt. The manpage will explain how to call this function and what parameters it expects.

    You may access the C code from text link on the CS112 home page to extract the code for insertion and selection sorts (might save you some time typing). Follow the Chapter 7 link on that webpage.

    This code will need to be modified for this lab, but the changes are minor. You should carefully design your changes before editing any code.

    Note that in the book, the functions use three types (List, Position, and ListEntry) which in our case are all going to be int's, so we have typedef'd them in sort.h to avoid a significant departure from the book examples.

    Section 5: Handing in your C code and answers

    When you have completed this lab assignment, you should have the following program(s) in your ~/cs112/lab7 directory:

  • main.c (containing the function main( ))
  • sort.c (containing all sorting functions)
  • sort.h (containing all typedefs, prototypes, etc.)
  • makefile

    Then, to submit your program(s) for grading, issue the command

    ~cs112/submit lab7

    at your UNIX prompt. This utility program will copy your programs for grading and an electronic mail message will be sent to you to acknowledge your submission. You may check the status of your submission at any time by typing the command

    ~cs112/query lab7

    at your UNIX prompt. You will automatically receive an electronic mail message confirming the status of your lab submission.

    You should also answer the questions below and submit them in hardcopy to the TAs at the beginning of lab on April 4 (no late submissions accepted).

    This week's questions

    For credit on this lab, your software must be received by midnight April 3 and your answers to the lab questions must be received at the beginning of lab on Friday, April 4.

    Note: Always bring your ID with you to lab.