📄 llist2.h
字号:
/*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. ClarkLast 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. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -