You are on page 1of 4

# Single and Doubly Linked Lists: 1.

A series of structures connected with pointers can be used to implement the data structures. Each structure contains data with one or more pointers to neighboring structures.

There are several variants of the linked list structure: Endogenous / Exogenous lists:
- endogenous lists have the data stored in the structure's KEY. The KEY is data stored within the structure. - e ogenous lists have the data stored outside the structure. !nstead of a KEY" the structure has a pointer to the data in memor#. E ogenous lists do not re\$uire data to be moved when individual cells are moved in a list% onl# the pointers to data must be changed. This can save considerable cost when dealing with large data in each cell. Another benefit of e ogenous lists is man# cells can point to the same data. Again" this ma# be useful depending on the application.

## &ere are e ample declarations of endogenous and e ogenous structures:

struct endogenous ' data(t#pe ke#" struct endogenous ) ne t *% struct e ogenous ' data(t#pe ) data" struct e ogenous ) ne t *%

## Circular / Non-circular lists:

- a circular list has the last cell in the arra# pointing to the first cell in the arra#. +pecificall#" the last cell's 'ne t' pointer references the first cell. ,epresentation in - : last(cell.ne t . /first(cell - the last cell in a non-circular list points to nothing. ,epresentation in - : last(cell.ne t . 0122 -ircular lists are useful for representing pol#gons 3for e ample4 because one can trace a path continousl# back to where one started. This is useful for representing a pol#gon because there is essentiall# no starting or ending point. Thus" we would like an implementation to illustrate this.

- a header node is a dumm# first node in the list. !t is not part of the data" but rather contains some information about the list 3eg. si6e4. - a trailer node is at the end of a list 3its contents marks the end4.

-each node in a doubl# linked list is a structure with two pointers to link with neighboring nodes. 7ne pointer points to the ne t node in the list" and the other pointer points to the previous node in the arra#. This implementation is useful for deleting nodes. The algorithm can be performed in 7354 time. 8eleting nodes in a singl# linked list can be done in 79E:A3n4 time. Therefore" doubl# linked lists can be ver# useful in applications re\$uiring a lot of deletions. The pseudocode for the delete algorithm is as follows:

## #\$\$lications 1. %olyno&ial #D":

A pol#nomial can be represented with primitive data structures. <or e ample" a pol#nomial represented as ak k ak-5 k-5 = ... = a> can be represented as a linked list. Each node is a structure with two values: ai and i. Thus" the length of the list will be k. The first node will have 3a k" k4" the second node will have 3ak-5" k-54 etc. The last node will be 3a>" >4. The pol#nomial ? @ = A ? = B can be represented in a list as follows: 3?"@4 --; 3A"?4 --; 3B">4 where each pair of integers represent a node" and the arrow represents a link to its neighbouring node. 8erivatives of pol#nomials can be easil# computed b# proceeding node b# node. !n our previous e ample the list after computing the derivative would represented as follows: 3CA"D4 --; 3C5"C4. The specific pol#nomial A8T will define various operations" such as multiplication" addition" subtraction" derivative" integration etc. A pol#nomial A8T can be useful for s#mbolic computation as well. C

## '. Large (nteger #D":

2arge integers can also be implemented with primitive data structures. To conform to our previous e ample" consider a large integer represented as a linked list. !f we represent the integer as successive powers of 5>" where the power of 5> increments b# ? and the coefficient is a three digit number" we can make computations on such numbers easier. <or e ample" we can represent a ver# large number as follows: B5?35>E4 = D@@35>?4 = ACC35>>4. 1sing this notation" the number can be represented as follows: 3B5?4 --; 3D@@4 --; 3ACC4. The first number represents the coefficient of the 5>E term" the ne t number represents the coefficient of the 5>? term and so on. The arrows represent links to adFacent nodes. The specific A8T will define operations on this representation" such as addition" subtraction" multiplication" division" comparison" cop# etc.

).

## indow *anager #D":

A window interface can be represented b# lists. -onsider an environment with man# windows. The fist node in the list could represent the current active window. +ubse\$uent windows are further along the list. !n other words" the n th window corresponds to the nth node in the list. The A8T can define several functions" such as <ind(first(window which would bring a window clicked upon to the front of the list 3make it active4. 7ther functions could perform window deletion or creation.

## +. *anage&ent o, ,ree s\$ace:

Ghen memor# is re\$uested" a list of available blocks of memor# might be useful. Again" a list could represent blocks in memor# available to the user" with nodes containing pointers to these available blocks. The list can be used like a stack 32!<74. The last freed memor# becomes the ne t available to the user. +uch lists are called 'free space lists' or 'available space lists'. +ince addition and deletion of nodes is at one end" these lists behave like stacks. All operations on free space lists can be done in 7354 time.

A linked list in which each node is linked to both its successor and its predecessor. templateHclass !temT#pe; struct 0odeT#pe ' !temT#pe info% 0odeT#peHitemT#pe;) ne t% 0odeT#peHitemT#pe;) previous% *% A linear doubl# linked list is defined in the following picture.0ote that previous member of the node and ne t member of last node" contains a 0122. The following definition might be used to declare the nodes in such a list: templateHclass !temT#pe; struct 0odeT#pe ' !temT#pe info% 0odeT#peHitemT#pe;) ne t% 0odeT#peHitemT#pe;) previous% *%
listdata 8avid Jud# 9aria ,obert

listdata

8avid

Jud#

9aria

,obert

new0ode

2eah

listdata

8avid

Jud#

9aria

,obert

location