Lists are another very basic data structure. Despite that they are actually quite varied.
Essentially a list consists of blocks of memory linked together with pointers. How they are linked and how they are accessed determines the type of list.
The first distinguishing factor is the number of links. If there is only one link this is a singly linked list. Singly linked lists can only be traversed in one direction, but are quite small because they only have one pointer. Lists with both a forward and back pointer are called double linked lists. These lists can be traversed both forward and backwards. Also you can easily delete an element from the center of a list since you have pointers to both the last element and the next element. Finally there are lists with more than two links. They generally allow you to traverse your data in more than one way and are only used for specialized purposes.
The second distinguishing factor is the location of the link. If the link is stored in the element then this is called an endo list. If the link is stored external to the element then this is an exo list. Most lists you will encounter are exo lists. They are slightly more expensive but make up for that by being more flexible.
The last distinguishing factor of lists is where they are accessed. If you insert and delete at only one end, then the list is a stack. If you insert at one end and delete from the other then the list is a queue. If you insert and delete from both ends then this is a dequeue.
Essentially a list consists of blocks of memory linked together with pointers. How they are linked and how they are accessed determines the type of list.
The first distinguishing factor is the number of links. If there is only one link this is a singly linked list. Singly linked lists can only be traversed in one direction, but are quite small because they only have one pointer. Lists with both a forward and back pointer are called double linked lists. These lists can be traversed both forward and backwards. Also you can easily delete an element from the center of a list since you have pointers to both the last element and the next element. Finally there are lists with more than two links. They generally allow you to traverse your data in more than one way and are only used for specialized purposes.
The second distinguishing factor is the location of the link. If the link is stored in the element then this is called an endo list. If the link is stored external to the element then this is an exo list. Most lists you will encounter are exo lists. They are slightly more expensive but make up for that by being more flexible.
The last distinguishing factor of lists is where they are accessed. If you insert and delete at only one end, then the list is a stack. If you insert at one end and delete from the other then the list is a queue. If you insert and delete from both ends then this is a dequeue.
Comments
Post a Comment