-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkedLists.h
78 lines (65 loc) · 3.33 KB
/
LinkedLists.h
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
/******************************************************************************
* Base struct to contain data structure element information: deterimined by
* the application needs.
******************************************************************************/
#ifndef _LINKED_LISTS_H_
#define _LINKED_LISTS_H_
typedef struct ElementStructs{
/* Application Specific Definitions */
char * word;
int index;
} ElementStructs;
/************** Nothing else in the module needs to be modified *************/
/******************************************************************************
* Base struct of list nodes, contains user information and link pointers.
* The "ElementStructs" typemark must be defined based on specific needs of the
* application.
******************************************************************************/
typedef struct LinkedListNodes
{
/* The user information field */
ElementStructs *ElementPtr;
/* Link pointers */
struct LinkedListNodes *Next;
struct LinkedListNodes *Previous;
} LinkedListNodes;
/******************************************************************************
* Base struct used to manage the linked list data structure.
******************************************************************************/
typedef struct LinkedLists
{
/* Number of elements in the list */
int NumElements;
/* Pointer to the front of the list of elements, possibly NULL */
struct LinkedListNodes *FrontPtr;
/* Pointer to the end of the list of elements, possibly NULL */
struct LinkedListNodes *BackPtr;
} LinkedLists;
/******************************************************************************
* Initialized the linked list data structure
******************************************************************************/
void InitLinkedList(LinkedLists *ListPtr);
/******************************************************************************
* Adds a record to the front of the list.
******************************************************************************/
void AddToFrontOfLinkedList(LinkedLists *ListPtr, ElementStructs *DataPtr);
/******************************************************************************
* Adds a record to the back of the list.
******************************************************************************/
void AddToBackOfLinkedList(LinkedLists *ListPtr, ElementStructs *DataPtr);
/******************************************************************************
* Removes (and returns) a record from the front of the list ('works' even on
* an empty list by returning NULL).
******************************************************************************/
ElementStructs *RemoveFromFrontOfLinkedList(LinkedLists *ListPtr);
/******************************************************************************
* Removes (and returns) a record from the back of the list ('works' even on
* an empty list by returning NULL).
******************************************************************************/
ElementStructs *RemoveFromBackOfLinkedList(LinkedLists *ListPtr);
/******************************************************************************
* De-allocates the linked list and resets the struct fields as if the
* list was empty.
******************************************************************************/
void DestroyLinkedList(LinkedLists *ListPtr);
#endif /* _LINKED_LISTS_H_ */