University of Minnesota
Introduction to Operating Systems
index.php

Not graded – No submission needed – To be done individually

1. Introduction

The purpose of this assignment is to get you going with C programming and make you comfortable with the Unix programming environment for subsequent assignments.

Note: You must make an attempt to work on this assignment individually (not with your project partner). The goal is to get you comfortable and ready to work on graded programming assignments when they are released. If you struggle with completing this assignment, you are likely to have significant difficulty in the subsequent assignments. You must try to brush up on your C programming skills – you can use some of the C programming references listed on the course References page as well.

2. Basic Assignment

Write a program that reads in a sequence of integers into a linked list, and prints the integers in a sorted order.

The number of integers (length of the list) 'n' should be provided as a commandline argument, and your program should then read n integers from the standard input.

3. Topics Covered

This assignment is meant to cover basic C programming, simple I/O, dynamic memory allocation, and pointer manipulation.

4. Helpful Hints

  • Think of the program design before coding.

  • Try to organize and think how your program can be constructed from smaller pieces or modules: e.g.: how to read in commandline arguments, how to read in integers, how to insert/sort them into the linked list, how to print the linked list, etc.

  • Try to use smaller functions (e.g., one function for each module) rather than implementing the whole program in a single main() function.

  • There may be different ways to achieve the same functionality. E.g.: to get a sorted list, you could either insert the integers in a sorted order, or sort the list after inserting all the elements. You can decide what would be a good approach for your program design.

  • It is a good idea to handle different kinds of errors that may occur during execution. E.g.: what if there are fewer or more commandline arguments (or integers in the input) than expected, what if there is a NULL pointer encountered while traversing the linked list, how to insert an integer into an empty linked list, etc. Try passing negative or very large values of n.

  • Use documentation throughout your code so someone else can read and understand the code. E.g.: use readable function and variable names, briefly describe the purpose of each function, add comments where needed, use proper indentation.

  • While running the program, you may use input redirection from a file to make it easier to pass input to your program.

  • You may use CSELabs machines to compile and execute your program.

5. Variations and Extensions

You may want to try some variations and extensions to the basic assignment above to make it more challenging, get more practice with C programming, and think more about data structures/algorithms. Here are some suggestions, though you are also encouraged to come up with other variants on your own. The more practice with C programming you can get, the easier it would for you to work on subsequent assignments.

  • Pass and sort strings of characters (words) instead of integers.
  • Try different sorting algorithms (e.g., bubblesort vs. insertion sort).
  • Instead of a linked list, try using a different data structure such as a heap or a binary tree.