member 1 : an array of elements
member 2 : last -- indicates position of the last element of the list
typedef int elementtype; /* elements are integers */
typedef struct list-tag {
elementtype elements [maxlength];
int last;
} list-type;
end(L)
int end (list-type
*p)
{
return (p
last + 1)
}
Insert (x, p,L)
void insert (elementtype x ; int p ; list-type *p) ;
{
int v; /* running position */
if (p last >= maxlength-1)
error (``list is full'')
elseif ((p < 0) || (p > p last + 1))
error (position does not exist)
else
for (q = p last ; q <= p, q-)
p elements [q + 1] = p elements [q] ;
p last = p last + 1 ;
p elements [p] = x
}
Delete (p, L)
void delete (int p ; list-type *p)
{
int q ; /* running position */
if ((p > p last) || (p < 0))
error (``position does not exist'')
else /* shift elements */ {
p last - ;
for (q = p ; q <= p last; q ++)
p elements [q] = p elements [q+1]
}
}
Locate (x, L)
int locate (element type *x ; list-type *p)
{
int q ;
for (q = 0 ; q <= p last ; q++)
if (p elements [q] = = x]
return (q) ;
return (p last + 1) /* if not found */
}