CMSC 223 Systems Programming
Fall 2023


Assignment#3
Due in Class on October 4.

  1. IS THE ARRAY SORTED? Write a function sorted(A, n) that returns true/false (or 1/0) depending on whether the array, A with n elements is sorted.
    Create a program sort.c that initializes an array as shown below:

    - Initialize an array of 10 integers so that A[i] = i.
    - Test to see if it is sorted, using the sorted(...) function.
    - It should print out the contents of the array on a single line, followed by the word (Sorted/Unsorted).

    Next, after initializing the array as above, add the command, A[5] = -9
    Run the program again, as above. Show your output for both cases.

  2. SORTING: Inserion Sort
    Implement the Insertion Sort algorithm as a function iSort(A, n)/iSort(n, A), to sort an array of n integers. First, do the following:

    - Initialize an array A, of 10 integers.
    - Shuffle the array (write a function called shuffle(A, n)/shuffle(n, A)). Consult class notes.
    - test and print the result of sorted(...) [exactly as you did in (1) above.]
    - Sort the array using iSort()
    - Test and print the result of sorted(...) [exactly as you did in (1) above.]

Scripting in Linux
Once done, you will need to show the sample runs of programs, as required above. In order to record the runs, you can use the Linux command script.
Go to your Assignment directory and enter the command: script session

You will get your command prompt back. Next, run each of the above programs as you normally would. Once done, enter the command: exit (or CTRL-D)

This will end your script session. If you now look a the contents of the session file, you will see that the entire interaction has been recorded in it (as a script!).

What to hand in:

A PDF document (by e-mail) containing the followiing:

Back to CMSC223 Home page