[go: up one dir, main page]

Menu

[r69]: / trunk / xmdview-1.1 / llist2.h  Maximize  Restore  History

Download this file

105 lines (87 with data), 2.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
/*
llist2.h
- Header file for an implementation of a dynamically
allocated linked list.
- Each node of the list contains 2 data elements and links to
previous and next nodes in the list.
- The list itself consists of links to the first (head) and
last (tail) nodes in the list, an error message, and a flag
for whether the list is closed or not (whether there are any
NULL links in the list).
Created By: David G. Clark
Last Modified: 06/23/97
*/
/*
Defines
*/
#ifndef BOOLEAN
#define BOOLEAN int
#define TRUE 1
#define FALSE 0
#define UNDEF -1
#endif
#define InfoType_t int
/*
Structure Definitions
*/
typedef enum {
NoErr,
MemErr,
NullErr,
ClosedErr
} ErrorCode_t;
typedef struct LNode_t {
struct LNode_t *Next;
struct LNode_t *Prev;
InfoType_t Mark;
long Step;
} ListNode_t;
typedef ListNode_t *Link_t;
typedef struct {
Link_t Head;
Link_t Tail;
ErrorCode_t Error;
BOOLEAN Closed;
} LinkList_t;
/*
Linked List Function Headers
*/
void InitList(LinkList_t *list);
/* Sets Head and Tail to NULL, Error to NoErr,
and Closed to FALSE. */
BOOLEAN IsListError(LinkList_t list);
/* Returns FALSE if Error is NoErr, and
TRUE otherwise. */
void PrintListError(FILE *output, LinkList_t list);
/* Prints error specific messages to output using
a switch (list.Error) statement. */
BOOLEAN AddNodeToList(LinkList_t *list, InfoType_t pos, long step);
/* If list is closed or not enough memory to allocate
a new node, returns FALSE. Otherwise, creates a new
node, copies the data elem into it, links to the
end of the list, and returns TRUE. */
BOOLEAN RemLastNodeFromList(LinkList_t *list);
/* If list is closed or null, returns FALSE. Otherwise,
removes the last node from the list, updating the
appropriate links, and returns TRUE. */
BOOLEAN RemFirstNodeFromList(LinkList_t *list);
/* If list is closed or null, returns FALSE. Otherwise,
removes the first node from the list, updating the
appropriate links, and returns TRUE. */
int ListLength(LinkList_t list);
/* Returns the length (number of nodes) in
the list as an integer. */
void FreeList(LinkList_t *list);
/* Parses through the list, freeing the memory
used by every node until done. Calls OpenList. */
void CloseList(LinkList_t *list);
/* Links list->Head to list->Tail and sets
list->Closed to TRUE. */
void OpenList(LinkList_t *list);
/* Sets list->Head->Prev and list->Tail->Next to NULL,
and list->Closed to FALSE. */
void PrintList(FILE *output, LinkList_t list);
/* Parses through the list, printing the data
contained in each node to output. Very
primitive, must be changed if InfoType_t
is changed. */