NODElib Documentation

By Gary William Flake

NAME

list.h - generic doubly linked lists

SYNOPSIS

This module defines a linked list for objects that can be expressed as a void pointer. Just the basics are provided.

#include <list.h>

LIST *list_create(void);

void list_destroy(LIST *list);

void list_destroy_all(LIST *list);

LIST_NODE *list_node_create(void *data);

void *list_node_destroy(LIST_NODE *node);

void list_insert_head(LIST *listLIST_NODE *node);

void list_insert_tail(LIST *listLIST_NODE *node);

void list_insert_before(LIST *list,
      LIST_NODE *
node,
      LIST_NODE *
refnode);

void list_insert_after(LIST *list,
     LIST_NODE *
node,
     LIST_NODE *
refnode);

LIST_NODE *list_remove_head(LIST *list);

LIST_NODE *list_remove_tail(LIST *list);

void list_remove_node(LIST *listLIST_NODE *node);

void list_do_func(LIST *list,
    void (*
func)(void *data));

LIST_NODE *list_search(LIST *list, void *data);

DESCRIPTION

Type Declarations

The following types are defined in the header file list.h.

LIST_NODE

typedef struct LIST_NODE {
  struct LIST_NODE *next, *prev;
  void *data;
} LIST_NODE;

A list node contains pointers to next and previous nodes and a pointer to its data. That's it.

LIST

typedef struct LIST {
  LIST_NODE *head, *tail;
  unsigned count;
} LIST;

The list itself consists only the pointers to the head and tail.

Function Definitions

The following function prototypes are given in the header file list.h.

LIST *list_create(void);

Create and empty list.

void list_destroy(LIST *list);

Destroy just the LIST structure (and not any nodes).

void list_destroy_all(LIST *list);

Destroy the LIST structure and all of its nodes.

LIST_NODE *list_node_create(void *data);

Create a list node with data as it's data.

void *list_node_destroy(LIST_NODE *node);

Destroy a node and return it's data value.

void list_insert_head(LIST *listLIST_NODE *node);

Insert node at the front of list.

void list_insert_tail(LIST *listLIST_NODE *node);

Insert node at the rear of list.

void list_insert_before(LIST *list,
      LIST_NODE *
node,
      LIST_NODE *
refnode);

Insert node before refnode in list.

void list_insert_after(LIST *list,
     LIST_NODE *
node,
     LIST_NODE *
refnode);

Insert node after refnode in list.

LIST_NODE *list_remove_head(LIST *list);

Remove the first node and return it.

LIST_NODE *list_remove_tail(LIST *list);

Remove the last node and return it.

void list_remove_node(LIST *listLIST_NODE *node);

Remove node from list.

void list_do_func(LIST *list,
    void (*
func)(void *data));

Call func on every data field in list, starting with the head and ending with the tail..

LIST_NODE *list_search(LIST *list, void *data);

Search for a node with that matches data and return the node.

AUTHOR

Gary William Flake (gary.flake@usa.net).