You are on page 1of 3

CURSOR IMPLEMENTATION: Cursor linked list is implemented without using pointers and it is easier to understand.

They instead use arrays of objects. They usually start with a Freelist and you can allocate space from it when needed. Cursor implementation is very useful where linked list concept has to be implemented without using pointers. If linked list are required and pointers are not available, then an alternative implementation must be used. The method we will describe is known as a cursor implementation. Data are stored in a global array of structures. Here array index is considered as an address. It maintains a list of free cells called cursors space in which slot 0 is considered as a header and Next is equivalent to the pointer which points to the next slot. The two important features present in a pointer implementation of linked list are as follows. 1. The data are stored in a collection of structures. Each structure contains data and a pointer to the next structure. 2. A new structure contains data from the systems global memory by a call to malloc and released by a call to free. INITIALIZED CURSOR SPACE Slot 0 1 2 3 4 5 6 7 8 9 Element Next 1 2 3 4 5 6 7 8 9 0

Cursor implementation must be able to simulate this. The logical way to satisfy condition 1 is to have a global array of structures for any cell in the array; its array index can be used in place of an address. We must now simulate condition 2 by

allowing the equivalent of malloc and free for cells in the cursor space array. To do this, we will keep a list (the free list) of cells that are not in any list. CURSOR IMPLEMENTATION OF LINKED LIST

Slot 0 1 2 3 4 5 6 7 8 9 10

Element B F Header Header C D E A

Next 6 9 0 7 0 10 4 8 2 0 1

The list will use cell 0 as a header. A value of 0 for Next is the equivalent of a NULL pointer. The initialization of cursor space is a straightforward loop, which we leave as an exercise. To perform a malloc, the first element (after the header) is removed from the free list. To perform a free list, we place the cell at the front of the free list. Notice that if there is no space available, our routine does the correct thing by setting header node. If the value of L is 5 and the value of M is 3, then L represent the list a, b, and e. a b e P = 0. This indicates that there are no more cells left. The cursor implementation of linked lists is straightforward. We will implement our lists with a

M represents the list c, d, and f.

To write the function for a cursor implementation of linked list we must pass and return the identical parameters as the pointers implementation. The routines are straightforward. Check whether the list is empty or not and check whether the current position is the last in a linked list. The function Find is returns the position of X in list L. The deletion is used to delete the element from the list. Again, the interface for the cursor implementation is identical to the pointer implementation. The cursor implementation could be used instead of the linked list implementation, with virtually no change required in the rest of the code. If relatively few finds are performed, the cursor implementation could be significantly faster because of the lack of memory management routines. Cursor operation simulates the features Collection of structures uses array for nodes Array index is pointer new and delete operation Keep a free list new returns an element from freelist delete place the node in freelist Freelist Use cell 0 as header All nodes are free initially 0 is a NULL pointer Comparison on Pointer Implementation and Curson Implementation of Linked List. 1. Data are stored in a collection of structures. Data are stored in a global array .Each structure contains a data and next structures. Here array index is pointer. considered as an address. 2. Malloc function is used to create a node and It maintains a list of free cells called free function is used to released the cell. cursors space in which slot 0 is considered as a header and Next is equivalent to the pointer which points to the next slot.