Computer Science: Abstraction to Implementation

ion could be shown as in Figure 4, where the numbers at the left are the indices of the boxes. We use an index value of –1 to represent the null pointer. The empty boxes are currently unused. With this representation, we also need to keep track of the first element, which in this case is the one at index 0. Note that there can be many representations for a single abstraction; this is a common phenomenon. Figure 4: A representation, using indices, for a linked list of four elements At the representation level, in order to insert a new element, we simply obtain a new box for it and adjust the structure accordingly. For example, since the box at index 1 is unused, we can use it to hold the new element. Suppose the element is e anl it is to be inserted after b. The new representation picture would be as shown in Figure 5 Figure 5: A representation for the modified linked list, of five elements c d b 0 1 2 3 4 5 a 3