CISC 3142
Programming Paradigms in C++
Lab #5
Arrays and Pointers — Tagsort

How to Develop and Submit your Labs

Lab 5 — Tagsort

The sorting techniques you've learned until now manipulate the array of data — swapping, sliding, and in general, moving the elements around until they are in sorted order. This can be undesirable for two reasons: Tagsort is a sorting technique that avoids these two problems. The basic idea is to maintain a secondary array (sometimes called an index or tag array) containing some sort of reference to the corresponding elements of the actual data array.

The tags are often implemented as integers corresponding to the subscripts (locations) of the elements in the data array:

Before sorting:
(index)         0   1   2   3   4
              +-------------------+
data array:   | 4 | 7 | 1 | 8 | 5 |
              +-------------------+

              +-------------------+
tag array :   | 0 | 1 | 2 | 3 | 4 |
              +-------------------+
After sorting:
(index)         0   1   2   3   4
              +-------------------+
data array:   | 4 | 7 | 1 | 8 | 5 |
              +-------------------+

              +-------------------+
tag array:    | 2 | 0 | 4 | 1 | 3 |
              +-------------------+
Iterating through the tag array after the sort, following the tags, and printing the values produces:
1 4 5 7 8
however, pointers often take the place of the integers. In the following example, the array begins at location 0100 (and each integer element is 4 bytes in length):
Before sorting:
(index)         0   1   2   3   4
              +-------------------+
data array:   | 4 | 7 | 1 | 8 | 5 |
              +-------------------+

              +-------------------+
tag array:    |100|104|108|10A|200|
              +-------------------+
After sorting:
(index)         0   1   2   3   4
              +-------------------+
data array:   | 4 | 7 | 1 | 8 | 5 |
              +-------------------+

              +-------------------+
tag array:    |108|100|200|104|10A|
              +-------------------+
and again, iterating through the pointers, and printing out the values at the other end of each pointer, results in:
1 4 5 7 8
Notes

The Details

Implementation Notes

Submitting to Codelab

Code Provided for this Lab