Go to the first, previous, next, last section, table of contents.


Double linked list

Author(s): David Trallero Mena.

Version: 1.10#7 (2006/4/26, 19:22:13 CEST)

Version of last change: 1.9#116 (2003/12/1, 22:4:57 CET)

This library allows the user to work with double linked lists. An index is used for referencing the current element in the list. Such index can be modified by next and prev predicated. The value of the current index can be obtained with top predicate

Usage and interface (ddlist)

Documentation on exports (ddlist)

PREDICATE: null_list/1:

Usage: null_list(?NullList)

PREDICATE: next/2:

Usage: next(OldList, NewList)

PREDICATE: prev/2:

Usage: prev(OldList, NewList)

PREDICATE: insert/3:

Usage: insert(List, Element, NewList)

PREDICATE: insert_top/3:

Usage: insert_top(List, Element, NewList)

PREDICATE: insert_after/3:

Usage: insert_after(List, Element, NewList)

PREDICATE: delete/2:

Usage: delete(OldList, NewList)

PREDICATE: delete_top/2:

Usage: delete_top(OldList, NewList)

PREDICATE: delete_after/2:

Usage: delete_after(OldList, NewList)

PREDICATE: top/2:

Usage: top(List, Element)

PREDICATE: rewind/2:

Usage: rewind(OldList, NewList)

PREDICATE: forward/2:

Usage: forward(OldList, NewList)

PREDICATE: length/2:

Usage: length(List, Len)

PREDICATE: length_next/2:

Usage: length_next(List, Len)

PREDICATE: length_prev/2:

Usage: length_prev(List, Len)

REGTYPE: ddlist/1:

Usage: ddlist(X)

Other information (ddlist)

Two simple examples of the use of the ddlist library package follow.

Using insert_after

:- module( ddl1 , _ , [] ).

:- use_module( library(ddlist) ).

main(A,B):-
        % L = []
        null_list( L ),
        % L = [1]
        insert_after( L  , 1 , L1 ),
        % L = [1,2]
        insert_after( L1 , 2 , L2 ),
        % L = [1,3,2]
        insert_after( L2 , 3 , L3 ),
        % L = [1,3,2] => A = [1]
        top( L3 , A ),
        % L = [3,2]
        next( L3 , PL3 ),
        % L = [3,2] => A = [3]
        top( PL3 , B ).

More Complex example

:- module( ddl2 , _ , [] ).

:- use_module( library(ddlist) ).

main(A,B):-
        % L = []
        null_list( L ),
        % L = [1]
        insert_after( L  , 1 , L1 ),
        % L = [1,2]
        insert_after( L1 , 2 , L2 ),
        % L = [1,2]
        insert( L2 , 3 , L3 ),
        % L = [3,1,2]
        prev( L3 , PL3 ),
        % L = [],
        forward( PL3 , FOR ),
        % L = [2]
        prev( FOR , FOR1 ),
        % L = [2] => A = 2
        top( FOR1 , A ),
        % L = [1,2]
        prev( FOR1 , FOR2 ),
        % L = [2]
        delete_after( FOR2 , FOR3 ),
        % L = [3,2]
        prev( FOR3, FOR4 ),
        % L = [3,2] => B = 3
        top( FOR4 , B ).


Go to the first, previous, next, last section, table of contents.