Next:2.2
Implementation of ListsUp:2.1
List Abstract Data TypePrevious:2.1
List Abstract Data Type
2.1.1 A Program with List ADT
A program given below is independent of which data structure
is used to implement the list ADT. This is an example of the notion of
encapsulation in object oriented programming.
Purpose:
To eliminate all duplicates from a list
Given:
-
1.
-
Elements of list L are of element type
-
2.
-
function same (x, y), where x and y are of
element type, returns
true if x and y are same, false
otherwise
-
3.
-
p and q are of type position
p : current position in L
q : moves ahead to find equal elements
Pseudocode in C:
{
p = first (L) ;
while (p! = end(L)) {
q = next(p, L) ;
while (q! = end(L)) {
if (same (retrieve (p,L), retrieve (q, L))))
delete (q,L);
else
q = next (q, L) ;
}
p = next (p, L) ;
}
}
Next:2.2
Implementation of ListsUp:2.1
List Abstract Data TypePrevious:2.1
List Abstract Data Type
eEL,CSA_Dept,IISc,Bangalore