Comp 121 – Introduction to Data Structures. Spring 2000

Programming Assignment 0 -- Due Thursday, Jan 20


Objective: To familiarize you with the programming environment you will be using for the remainder of this course.

Given an array A[0,...n-1], the bubblesort sorting algorithm sorts the array as follows:

for (i=n; i>1; i--)

for (j=0; j<i-1; j++)

if (A[j]>A[j+1]) swap(A[j],A[j+1]);

You are to write and test a program that reads in a list of floating-pont numbers from a file, sorts these numbers using the bubblesort algorithm, and writes the numbers out into another file. The input file will be formatted as follows:

n

a1

a2

a3

.

.

an

You must write, compile, and execute your program in the C++ programming language, using the GNU C++ compiler g++, on one of the Department Unix machines. You must use the <fstream.h> input-output facilities (you man not use fscanf/ fprintf instead). Try and use as many C++ features as possible, rather than simply using the C-subset of C++.

Rules for submitting this (and future) programs: