File: LinkedList.c

package info (click to toggle)
libconvert-binary-c-perl 0.86-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,264 kB
  • sloc: ansic: 47,836; perl: 4,980; yacc: 2,143; makefile: 61
file content (21 lines) | stat: -rw-r--r-- 829 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
MyObject  *pObj;                      // pointer to an object
LinkedList list;                      // linked list handle

list = LL_new();                      // create new linked list

LL_push(list, NewObject("Foo", 3));   // push a new object onto the list
LL_push(list, NewObject("Bar", 2));   // push a new object onto the list
LL_push(list, NewObject("Cat", 7));   // push a new object onto the list

LL_sort(list, CompareObjects);        // sort the list

printf("The list has %d elements\n",  // print the list's size
       LL_size(list));

LL_foreach(pObj, list)                // loop over all elements
  PrintObject(pObj);

pObj = LL_shift(list);                // shift off the first element
DeleteObject(pObj);                   // ...and delete it

LL_destroy(list, DeleteObject);       // destroy the whole list