31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6.8 Singly Linked Lists ( slist )<br />

1. Definition<br />

An instance L of the parameterized data type slist is a sequence of items (slist item).<br />

Each item in L contains an element of data type E, called the element type of L. <strong>The</strong><br />

number of items in L is called the length of L. If L has length zero it is called the empty<br />

list. In the sequel 〈x〉 is used to denote a list item containing the element x and L[i] is<br />

used to denote the contents of list item i in L.<br />

#include < <strong>LEDA</strong>/core/slist.h ><br />

2. Types<br />

slist:: value type<br />

the value type.<br />

3. Creation<br />

slist L;<br />

slist L(const E& x);<br />

creates an instance L of type slist and initializes it to the<br />

empty list.<br />

creates an instance L of type slist and initializes it to the<br />

one-element list 〈x〉.<br />

4. Operations<br />

int L.length( ) returns the length of L.<br />

int L.size( ) returns L.length().<br />

bool L.empty( ) returns true if L is empty, false otherwise.<br />

slist item L.first( ) returns the first item of L.<br />

slist item L.last( ) returns the last item of L.<br />

slist item L.succ(slist item it) returns the successor item of item it, nil if it =<br />

L.last().<br />

Precondition: it is an item in L.<br />

slist item L.cyclic succ(slist item it) returns the cyclic successor of item it, i.e., L.first()<br />

if it = L.last(), L.succ(it) otherwise.<br />

const E& L.contents(slist item it)<br />

const E& L.inf(slist item it)<br />

returns the contents L[it] of item it.<br />

Precondition: it is an item in L.<br />

returns L.contents(it).<br />

Precondition: it is an item in L.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!