view include/LinkedList.h @ 4:c9e6f5c0a9b2

Added copyright notices, COPYING and README files.
author Eris Caffee <discordia@eldalin.com>
date Fri, 22 Jul 2011 20:45:30 -0500
parents 112164f48f30
children
line source
1 /*******************************************************************************
2 * linked_list
3 *
4 * A simple doubly linked list class in C.
5 *
6 *******************************************************************************
7 *
8 * Copyright (C) 2010 Sarah Eris Horsley Caffee
9 *
10 * This is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 *
23 *******************************************************************************
24 *
25 * Not thread safe.
26 *
27 * Since this class does not attempt to manage memory for the actual stored
28 * objects, there is no "clear" method to delete the entire list. Instead,
29 * the user must pop the entire list and delete the individually returned
30 * objects one at a time.
31 *
32 * A potential improvement would be to allow the registration of an object
33 * destructor at list creation which could then be used by a clear() method.
34 *
35 *
36 *
37 *
38 * OOH SHINY!
39 * http://tinobox.com/wordpress/object-oriented-c-coding/
40 *
41 * Looks liks good stuff. Must read.
42 *
43 ******************************************************************************/
45 #ifndef LINKEDLIST_H
46 #define LINKEDLIST_H
48 typedef struct ll_node ll_node;
50 typedef struct LinkedList LinkedList;
51 struct LinkedList
52 {
53 /* Public */
54 void * (* push) (LinkedList * this, void * data);
55 void * (* pop) (LinkedList * this);
56 void * (* insert)(LinkedList * this, void * data);
57 void * (* remove)(LinkedList * this);
58 void * (* insert_at_head)(LinkedList * this, void * data);
59 int (* size) (LinkedList * this);
60 void * (* head) (LinkedList * this);
61 void * (* tail) (LinkedList * this);
62 void * (* next) (LinkedList * this);
63 void * (* prev) (LinkedList * this);
64 void * (* data) (LinkedList * this);
66 /* Private (notionally, at least) */
67 ll_node * Head;
68 ll_node * Curr;
69 ll_node * Tail;
70 int Size;
71 };
73 /* Forward declarations for more traditional C usage. */
75 void ll_init (LinkedList * this);
76 void * ll_push (LinkedList * this, void * data);
77 void * ll_pop (LinkedList * this);
78 void * ll_insert(LinkedList * this, void * data);
79 void * ll_remove(LinkedList * this);
80 void * ll_insert_at_head(LinkedList * this, void * data);
81 int ll_size (LinkedList * this);
82 void * ll_head (LinkedList * this);
83 void * ll_tail (LinkedList * this);
84 void * ll_next (LinkedList * this);
85 void * ll_prev (LinkedList * this);
86 void * ll_data (LinkedList * this);
88 #endif