Singly Linked ListsThe data type slist can be used to store a number of objects of an arbitrary type T sequentially. Each element in the list knows its successor. Singly Linked Lists are closely connected to Linear Lists. The elements of a Singly Linked List are of typeslist_item.
ExampleThe following program shows how to use Singly Linked Lists. It generates anslist SL of int and appends the numbers 1 to 100 to SL.
Then it iterates over all elements of SL by starting at the first
element and always accessing the successor of the current element.
#include <LEDA/core/slist.h>
int main()
{
leda::slist<int> SL;
int i;
for (i=1; i<=100; i++) SL.append(i);
leda::slist_item lit=SL.first();
while (lit!=nil) { //you can also use the forall()-macro
std::cout << SL[lit] << " ";
lit=SL.succ(lit);
}
std::cout << std::endl;
return 0;
}
Strengths
Disadvantages
Tips
|
See also:Manual Entries: |