CSCI 333 Homework 4

This homework is not graded. It is practice for the Quiz 4.

Problem 1

Show the comparisions and exchanges made by the bad sorts, selection and insertion, on the following input set of six values:

  1. 3
  2. 7
  3. 15
  4. 13
  5. 2
  6. 5

Problem 2

Show how quicksort will partition the following array of nine values into two parts. Show the exchanges and comparisions made in the partitioning. You may choose the pivot.

  1. 3
  2. 19
  3. 7
  4. 13
  5. 15
  6. 2
  7. 17
  8. 5
  9. 23

Problem 3

Show how the good sorts, heapsort and mergesort, will sort the following list of eight values.

  1. 3
  2. 7
  3. 15
  4. 20
  5. 13
  6. 10
  7. 2
  8. 5

Problem 4

A file contains a sequence of integers, possibly separated by commas. Write a C++ subroutine which is passed an istream that has been opened to this file and returns the sum of all the integers in the file. Return -1 is the file is not in the correct format.

Here is an example of the file input:

   35  67, 89
13 5

13, 67

Here is a header for your function:

int SumEm(istream NumS)

Problem 5

Write some C++ statements to replace the fifth character of a file with the character 'X'.