source: npl/mediabox/lcdproc_edwin/src/old/llistd.h

Last change on this file was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 2.6 KB
Line 
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
40int * LLMakeFirstNode(int * first);     // Make a standalone node...
41
42int * LLFindFirst(int * current);       // returns address of First node
43int * LLFindNext(int * current);        // returns address of next node
44int * LLFindPrev(int * current);        // returns address of prev node
45int * LLFindLast(int * current);        // returns address of last node
46
47int * LLAddNode(int * current, int * add);      // Adds node AFTER current one
48int * LLInsertNode(int * current, int * add);   // Adds node BEFORE current one
49int * LLCutNode(int * cut);                     // Removes a node from the link
50
51int * LLPush(int * current, int * add);    // Add node to end of list
52int * LLPop(int * current);                // Remove node from end of list
53int * LLShift(int * current);              // Remove node from start of list
54int * LLUnshift(int * current, int * add); // Add node to beginning of list
55
56void  LLSwapNodes(int * one, int * two);   // Switch two nodes positions...
57
58int   LLCountNodes(int * current);      // Returns # of nodes in entire list
59
60// "Selection Sort"s the list and returns a pointer to the first node
61int * LLSelectSort(int * current, int compare(void *, void *));
62
63#endif
Note: See TracBrowser for help on using the repository browser.