| Bsoft 2.0.5 Bernard's software package

Functions | Variables
linked_list.cpp File Reference

Generalized linked list functions. More...

`#include "utilities.h"`

Go to the source code of this file.

## Functions
char * | add_item (char **list, unsigned long size)
| Adds an item to a linked list. More...
char * | append_item (char **list, char *item)
| Appends an item to a linked list. More...
char * | copy_item (char *toitem, char *fromitem, unsigned long size)
| Copies an item to an existing item without changing the link. More...
char * | remove_item (char **list, char *item, unsigned long size)
| Finds the given item and deletes it from the linked list. More...
char * | replace_item (char **list, char *item, char *new_item)
| Finds the given item and replaces it with the new item. More...
char * | copy_list (char *list, unsigned long size)
| Generates a complete copy of a linked list. More...
long | kill_list (char *list, unsigned long size)
| Frees all the items in a linked list. More...
long | count_list (char *list)
| Counts the number of items in a linked list. More...
long | reverse_list (char **list)
| Reverse the order of items in a linked list. More...

## Variables
int | verbose

## Detailed Description

Generalized linked list functions.

Author
  Bernard Heymann

Date
  Created: 20031203
  Modified: 20150206

Definition in file linked_list.cpp.

## Function Documentation

## ◆ add_item()

char* add_item | ( | char ** | list,
|  | unsigned long | size
| ) |  |

Adds an item to a linked list.

Parameters

  **list | pointer to first item in the list.
  size | size of item.

Returns
  char* new item.

      If the list is not defined, the new item becomes the first in the list.
      Otherwise, the list is traversed to find the end and the new item appended.
      Any structure with a pointer to itself as a first element can be used in a
      linked list. However, a linked list can only consist of one type of structure.

Definition at line 26 of file linked_list.cpp.

## ◆ append_item()

char* append_item | ( | char ** | list,
|  | char * | item
| ) |  |

Appends an item to a linked list.

Parameters

  **list | pointer to first item in the list.
  *item | item to append.

Returns
  char* item.

      If the list is not defined, the new item becomes the first in the list.
      Otherwise, the list is traversed to find the end and the new item appended.
      Any structure with a pointer to itself as a first element can be used in a
      linked list. However, a linked list can only consist of one type of structure.

Definition at line 59 of file linked_list.cpp.

## ◆ copy_item()

char* copy_item | ( | char * | toitem,
|  | char * | fromitem,
|  | unsigned long | size
| ) |  |

Copies an item to an existing item without changing the link.

Parameters

  *toitem | item to copy to.
  *fromitem | item to copy from.
  size | size of item.

Returns
  char* the resultant item.

      The items must be the same type.

Definition at line 87 of file linked_list.cpp.

## ◆ copy_list()

char* copy_list | ( | char * | list,
|  | unsigned long | size
| ) |  |

Generates a complete copy of a linked list.

Parameters

  *list | linked list.
  size | size of list item.

Returns
  char* new list.

Definition at line 185 of file linked_list.cpp.

## ◆ count_list()

long count_list | ( | char * | list | ) |

Counts the number of items in a linked list.

Parameters

  *list | first item in the linked list.

Returns
  long number of items in the list.

Definition at line 235 of file linked_list.cpp.

## ◆ kill_list()

long kill_list | ( | char * | list,
|  | unsigned long | size
| ) |  |

Frees all the items in a linked list.

Parameters

  *list | first item in the linked list.
  size | size of item.

Returns
  long number of items deallocated.

      The list is traversed, setting a pointer to the next item before
      deallocating the current item.

Definition at line 214 of file linked_list.cpp.

## ◆ remove_item()

char* remove_item | ( | char ** | list,
|  | char * | item,
|  | unsigned long | size
| ) |  |

Finds the given item and deletes it from the linked list.

Parameters

  **list | pointer to first item in the linked list.
  *item | item to be deleted.
  size | size of item.

Returns
  char* item after the one removed.

      If the item is the first in the list, the list pointer is set to point
      to the next item.
      Otherwise, the list is traversed to find the item, the previous item's
      pointer is set to the next item, and the current item deallocated.

Definition at line 114 of file linked_list.cpp.

## ◆ replace_item()

char* replace_item | ( | char ** | list,
|  | char * | item,
|  | char * | new_item
| ) |  |

Finds the given item and replaces it with the new item.

Parameters

  **list | pointer to first item in the linked list.
  *item | item to be replaced.
  *new_item | new item.

Returns
  char* new item.

      If the item is the first in the list, the list pointer is set to point
      to the new item.
      Otherwise, the list is traversed to find the item, the previous item's
      pointer is set to the new item, the new item's pointer is set to that
      of the old item, and the old item is deallocated.

Definition at line 152 of file linked_list.cpp.

## ◆ reverse_list()

long reverse_list | ( | char ** | list | ) |

Reverse the order of items in a linked list.

Parameters

  *list | first item in the linked list.

Returns
  long number of items in the list.

Definition at line 252 of file linked_list.cpp.

## Variable Documentation

## ◆ verbose

int verbose