CS 112ba
Fall 2000
Ileana Streinu

Lecture 3


  • Simple function calls in C. The swap function. Parameter passing in C and in C++. References versus pointers, a first example (we'll get back to this topic, in more detail, later in the semester).
  • Brief review of arrays in C and C++.

    Today: Demo on how to start working on a hwk, illustrated with a program for Selection Sort. Application for arrays, function calls and preparation for Hw2

  • Programming discipline:

    Selection Sort

    Input: an array of n integers.
    Output: the array in sorted order (increasing)
    Algorithm: Works in n iterations. At iteration i it finds the minimum element among the elements not yet sorted (which are all, at the first step), then swaps it with the element at position i. Thus after iteration i, the first i elements are sorted. After n steps, all are sorted.

    Here's what we did in class. Try to find the error in the last version of the program, which I put in V2Bad. And here is the version I wrote before class, sort.cpp.
    Hw 2