1 | #ifndef LLISTD_H |
---|
2 | #define LLISTD_H |
---|
3 | /***************************************************************************** |
---|
4 | * AUTHOR: Scott Scriven, SSN: 523-21-9640, CLASS: CS151.003, DATE: 96-11-21 |
---|
5 | ****************************************************************************** |
---|
6 | * Doubly Linked Lists! |
---|
7 | * This code will handle "generic" Doubly-Linked Lists. These lists can be |
---|
8 | * any type as long as they satisfy a few requirements: |
---|
9 | * Your structure must start with two integer pointers: |
---|
10 | * struct mystruct { |
---|
11 | * int *next, *prev; |
---|
12 | * ... |
---|
13 | * }; |
---|
14 | * That's all, pretty much. |
---|
15 | * |
---|
16 | * Most of the functions take integer pointers. This means you will have to |
---|
17 | * call them in one of the following ways: |
---|
18 | * function((int *)&mystruct); |
---|
19 | * function((int *)mystruct); |
---|
20 | * function(&mystruct.next); |
---|
21 | * |
---|
22 | ****************************************************************************** |
---|
23 | * If I'm not mistaken, this code should work regardless of your machine's |
---|
24 | * integer size (16/32/64/etc... bit) |
---|
25 | ****************************************************************************** |
---|
26 | * Note that we have to do NULL checking to make sure we don't try to write |
---|
27 | * to protected areas of memory if we reach the beginning/end of a list. |
---|
28 | * |
---|
29 | * We also do some circular-link checking to avoid infinite loops. |
---|
30 | * These loops will work fine: |
---|
31 | * a <-> b <-> c <-> a <-> b... |
---|
32 | * a <-> b <-> c -> c -> c... |
---|
33 | * This loop might make this code puke: |
---|
34 | * a <-> b <-> c <-> d -> c d <- e <-> f <-> g |
---|
35 | *****************************************************************************/ |
---|
36 | |
---|
37 | |
---|
38 | // See llistd.c for detailed descriptions of these functions. |
---|
39 | |
---|
40 | int * LLMakeFirstNode(int * first); // Make a standalone node... |
---|
41 | |
---|
42 | int * LLFindFirst(int * current); // returns address of First node |
---|
43 | int * LLFindNext(int * current); // returns address of next node |
---|
44 | int * LLFindPrev(int * current); // returns address of prev node |
---|
45 | int * LLFindLast(int * current); // returns address of last node |
---|
46 | |
---|
47 | int * LLAddNode(int * current, int * add); // Adds node AFTER current one |
---|
48 | int * LLInsertNode(int * current, int * add); // Adds node BEFORE current one |
---|
49 | int * LLCutNode(int * cut); // Removes a node from the link |
---|
50 | |
---|
51 | int * LLPush(int * current, int * add); // Add node to end of list |
---|
52 | int * LLPop(int * current); // Remove node from end of list |
---|
53 | int * LLShift(int * current); // Remove node from start of list |
---|
54 | int * LLUnshift(int * current, int * add); // Add node to beginning of list |
---|
55 | |
---|
56 | void LLSwapNodes(int * one, int * two); // Switch two nodes positions... |
---|
57 | |
---|
58 | int LLCountNodes(int * current); // Returns # of nodes in entire list |
---|
59 | |
---|
60 | // "Selection Sort"s the list and returns a pointer to the first node |
---|
61 | int * LLSelectSort(int * current, int compare(void *, void *)); |
---|
62 | |
---|
63 | #endif |
---|