6.s096 2013

Assignment 3

Assignments are due at midnight after the following lecture. This assignment was due on Thursday, January 17 at 11:59pm.

The companion lecture was Lecture 3: C Memory Management.

An example solution is now available.

- Problem 1

In sort.c, I've implemented a basic implementation of insertion sort (not too efficient, but a very simple sorting algorithm). Look at and understand the code (read comments), and put the proper argument data type for the sort function's first argument. Compile and run the code to make sure it works (it sorts the numbers).

Now, replace all array index access (places where I access the array with [], such as in A[i]) in the entire program by using pointer addition instead. Also, where I create the array (line 34, int array[n];), replace that with an array creation using malloc (of same size). Hint: Since we're using malloc, we must also make another change!

Make sure your program compiles and runs correctly (numbers are sorted).

- Problem 2

The purpose of resize.c is to create an initial array of a user-specified size, then dynamically resize the array to a new user-specified size. I've given a shell of the code, including code to get user-specified sizes as ints.

However, the code is missing a few things! You must manage the memory for the array! Look at the comments in the code that describe what should be done and fill in blanks. Make sure the program compiles and runs as expected.

- Submit

Athena Submission

If you're working on Athena, this is the easier way to submit. It's still being tested, though, so if you have any problems, tell us about them and submit with Stellar instead.

Just change into your assignment directory and invoke our athrun 6.s096 submit-assignment command like this:

$ cd assignment3
$ ls
reverse.c
sort.c
$ athrun 6.s096 submit-assignment . assignment3
Submitted:
/mit/6.s096/submissions/dynamic/assignment3.2013-01-15_14.02.53
├── resize.c
└── sort.c

0 directories, 2 files
$ echo heck yeah
heck yeah

Stellar Submission

Submit your version of the source files on Stellar.

That's easiest from an Athena cluster, but you can download your files from Athena too. First, compress them with a command like this:

tar zcvf assignment3-athenaid.tar.gz *.c *.h

Then you can download them with SCP. WinSCP is a good client for Windows. On Linux and OS X, you can use the scp command:

scp athenaid@athena.dialup.mit.edu:assignment3/assignment3-athenaid.tar.gz .

(Note the period at the end of the scp command!)