Below is sample program to demonstrate how to manipulate linked list.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <pj/list.h>
00021 #include <pj/assert.h>
00022 #include <pj/log.h>
00023
00032 struct my_node
00033 {
00034
00035 PJ_DECL_LIST_MEMBER(struct my_node);
00036 int value;
00037 };
00038
00039
00040 int main()
00041 {
00042 struct my_node nodes[10];
00043 struct my_node list;
00044 struct my_node *it;
00045 int i;
00046
00047
00048 pj_list_init(&list);
00049
00050
00051 for (i=0; i<10; ++i) {
00052 nodes[i].value = i;
00053 pj_list_insert_before(&list, &nodes[i]);
00054 }
00055
00056
00057 it = list.next;
00058 while (it != &list) {
00059 PJ_LOG(3,("list", "value = %d", it->value));
00060 it = it->next;
00061 }
00062
00063
00064 for (i=0; i<10; ++i) {
00065 pj_list_erase(&nodes[i]);
00066 }
00067
00068
00069 pj_assert( pj_list_empty(&list) );
00070
00071 return 0;
00072 };