Programming Exercise 3


For this exercise, you will need to download the template ex3.c, and enter your code in the methods (functions) provided. You are welcome to create your own methods if you like. You will also need to download two additional files - the test program ex3test.c and the file uniform.c. You may change or add test code to ex3test.c if you like. Both files need to be in the same directory as your ex2.c. Before you write your first line of code, you ought to try compiling the template as follows:

  gcc -o ex3 ex3test.c ex3.c uniform.c -lm
This will create an executable called ex3 that you can execute as follows:
  ./ex3

In this exercise you will get practice with linked lists and pointers in C. You will implement a doubly-linked list and manipulate it in certain ways. Let's look at some of the methods:

Once you have found the data, you will move that item up towards the front of the list. The idea is, if an item is frequently accessed, it's better to have it closer up near the front of the list. But since we have no way of knowing what's frequently accessed, we'll simply move each accessed item some distance towards the front. This way, over time, the frequently accessed items will tend to cluster near the front of the list.

How much do we move an item up towards the front? If moveDistance=1 that corresponds to moving the item up by one, i.e., by swapping it with the item that's next to it (in the direction towards the front). Similarly, if moveDistance is large, the move will probably move it right to the front of the list. The goal here is to experiment with different values of moveDistance. The test code provided experiments with a few such distances.

To evaluate a particular strategy, we need to simulate many lists and compute the average performance. The performance is defined as the average search depth required over a large number of accesses (say, 10,000 accesses).

Deliverables and submission: