diff options
author | cathook <cat.hook31894@gmail.com> | 2013-11-27 02:58:37 +0800 |
---|---|---|
committer | cathook <cat.hook31894@gmail.com> | 2013-11-27 02:58:37 +0800 |
commit | f4f4bdf4d551c28aad4e69fe4bd1c78ce85aaf7c (patch) | |
tree | 0433a7cd87f8a4f72ffbd7fd3f000726d656ecbf | |
parent | b05fa4a0fba350843db7b1121b74e1c60da14253 (diff) | |
download | ctl-f4f4bdf4d551c28aad4e69fe4bd1c78ce85aaf7c.tar.gz ctl-f4f4bdf4d551c28aad4e69fe4bd1c78ce85aaf7c.tar.zst ctl-f4f4bdf4d551c28aad4e69fe4bd1c78ce85aaf7c.zip |
contain test.c
-rw-r--r-- | include/list.h | 65 | ||||
-rw-r--r-- | src/list.c | 347 | ||||
-rw-r--r-- | test.c | 155 |
3 files changed, 469 insertions, 98 deletions
diff --git a/include/list.h b/include/list.h index c436a8a..535dfa9 100644 --- a/include/list.h +++ b/include/list.h @@ -69,25 +69,18 @@ /* Remove the first element of the list. */ /* */ /* */ -/* cat(addr of the l1, addr of the l2) */ -/* Concatenate the list1 to the back of list2. */ +/* rm(addr of the list, addr of the iter1, iter2) */ +/* Remove the part of iter1 ~ iter2 (include iter1 */ +/* but not iter2) */ /* */ -/* copy(addr of the l1, addr of the l2) */ -/* Let the contain in the l1 be the one in the l2 */ +/* copy(addr of the list, addr of the iter1, iter2) */ +/* Create a new list which contain the part of the */ +/* iter1 ~ iter2 (include iter1 but not iter2) */ /* */ -/* swap(addr of the iterator i1, i2, j1, j2) */ -/* Connect the i1 to the next element of j1. */ -/* Connect the j1 to the next element of i1. */ -/* Connect the previous element of i2 to j2. */ -/* Connect the previous element of j2 to i2. */ -/* */ -/* replace(addr of the iterator i1, count1, */ -/* addr of the iterator i2, coutn2) */ -/* Let i1, next of i1, next of next of i1, ..... */ -/* (number count1) be i2, next of i2, next of next of*/ -/* i2, ...... (number abs(count2)) */ -/* Note that if count2 < 0, this function will repl- */ -/* ace the data in reverse order. */ +/* swap(addr of the l1, addr of the iter. i1, i2, */ +/* addr of the l2, addr of the iter. j1, j2) */ +/* Swap the part of l1 from i1 to i2.previous and */ +/* the part of l2 from j1 to j2.previous. */ /* */ /* */ /* iterGetEntry(addr of the iteator) */ @@ -143,14 +136,16 @@ pvoid ctl_list_setFrontX(ppvoid l, pcvoid data); pvoid ctl_list_setBackX (ppvoid l, pcvoid data); int ctl_list_addFrontX(ppvoid l, pcvoid data); -int ctl_list_delFrontX(ppvoid l, pcvoid data); + +int ctl_list_delFrontX(ppvoid l); int ctl_list_addBackX (ppvoid l, pcvoid data); -int ctl_list_delBackX (ppvoid l, pcvoid data); +int ctl_list_delBackX (ppvoid l); -int ctl_list_catX (ppvoid l, ppcvoid l2); -pvoid ctl_list_copyX (ppvoid l, ppcvoid l2); -int ctl_list_replaceX(ppvoid i1, uint ct1, ppcvoid j1, int ct2); -void ctl_list_swapX (ppvoid i1, ppvoid i2, ppvoid j1, ppvoid j2); +int ctl_list_rmX (ppvoid l, ppvoid i1, ppvoid i2); +pvoid ctl_list_copyX(ppvoid l, ppvoid i1, ppvoid i2, ppvoid out); +pvoid ctl_list_moveX(ppvoid l, ppvoid i1, ppvoid i2, ppvoid out); +int ctl_list_swapX(ppvoid l1, ppvoid i1, ppvoid i2, + ppvoid l2, ppvoid j1, ppvoid j2); pcvoid ctl_list_iterGetEntryX(ppcvoid i); pvoid ctl_list_iterGetNextX (ppcvoid i); @@ -158,8 +153,8 @@ pvoid ctl_list_iterGetPrevX (ppcvoid i); pvoid ctl_list_iterSetEntryX(ppvoid i, pcvoid *data); -pvoid ctl_list_iterGoNextX(ppcvoid i); -pvoid ctl_list_iterGoPrevX(ppcvoid i); +pvoid ctl_list_iterGoNextX(ppvoid i); +pvoid ctl_list_iterGoPrevX(ppvoid i); pvoid ctl_list_iterDelX (ppvoid i); pvoid ctl_list_iterDelPrevX(ppvoid i); @@ -181,14 +176,20 @@ pvoid ctl_list_iterDelNextX(ppvoid i); #define ctl_list_setBack(X,Y) ctl_list_setBackX (ppVoid(X),pcVoid(Y)) #define ctl_list_addFront(X,Y) ctl_list_addFrontX(ppVoid(l),pcVoid(Y)) -#define ctl_list_delFront(X,Y) ctl_list_delFrontX(ppVoid(l),pcVoid(Y)) +#define ctl_list_delFront(X) ctl_list_delFrontX(ppVoid(l)) #define ctl_list_addBack(X,Y) ctl_list_addBackX (ppVoid(l),pcVoid(Y)) -#define ctl_list_delBack(X,Y) ctl_list_delBackX (ppVoid(l),pcVoid(Y)) - -#define ctl_list_cat(X,Y) ctl_list_catX (ppVoid(X),ppcVoid(Y)) -#define ctl_list_copy(X,Y) ctl_list_copyX(ppVoid(X),ppcVoid(Y)) -#define ctl_list_replace(X,Y,Z,A) ctl_list_replaceX(ppVoid(X),Y,ppcVoid(Z),A) -#define ctl_list_swap(X,Y,Z,A) ctl_list_swapX(ppVoid(X),ppVoid(Y),ppVoid(Z),ppVoid(A)) +#define ctl_list_delBack(X) ctl_list_delBackX (ppVoid(l)) + + +int ctl_list_rmX (ppvoid l, ppvoid i1, ppvoid i2); +pvoid ctl_list_copyX(ppvoid l, ppvoid i1, ppvoid i2, ppvoid out); +pvoid ctl_list_moveX(ppvoid l, ppvoid i1, ppvoid i2, ppvoid out); +int ctl_list_swapX(ppvoid l1, ppvoid i1, ppvoid i2, + ppvoid l2, ppvoid j1, ppvoid j2); +#define ctl_list_rm(X,Y,Z) ctl_list_rmX (ppVoid(X),ppVoid(Y),ppVoid(Z)) +#define ctl_list_copy(X,Y,Z,A) ctl_list_copyX(ppVoid(X),ppVoid(Y),ppVoid(Z),ppVoid(A)) +#define ctl_list_move(X,Y,Z,A) ctl_list_moveX(ppVoid(X),ppVoid(Y),ppVoid(Z),ppVoid(A)) +#define ctl_list_swap(X,Y,Z,A,B,C) ctl_list_swapX(ppVoid(X),ppVoid(Y),ppVoid(Z),ppVoid(A),ppVoid(B),ppVoid(C)) #define ctl_list_iterGetEntry(X) ctl_list_iterGetEntryX(ppcVoid(X)) #define ctl_list_iterGetNext(X) ctl_list_iterGetNextX (ppcVoid(X)) @@ -11,45 +11,82 @@ struct ListNodeStruct{ }; struct ListHeaderStruct{ - size_t size; - uint count; + size_t size; + uint count; struct ListNodeStruct data; }; -typedef struct ListNodeStruct ListNode; +typedef struct ListNodeStruct ListNode; typedef struct ListHeaderStruct ListHeader; -#define getHeader(X) (*(ListHeader**)(pChar(X)-offsetof(ListNode,buf))) +#define getHeader(X) (*(ListHeader**)(pChar(X)-offsetof(ListNode,buf))) +#define getNode(X) ((X)==NULL?NULL:*(ListNode*)(pChar(X)-offsetof(ListNode,buf))) #define getNodeSize(X) ((X)->size + sizeof(ListNode)) -/******************** static functions ********************/ -static void addNode0(ListHeader *l){ - ListNode *tmp = (ListNode*)ctl_malloc(getNodeSize(l)); - tmp->head = l; - tmp->prev = NULL; - tmp->next = NULL; - l->count = 1; - l->data.prev = tmp; - l->data.next = tmp; -} -static void addNodeBack(ListHeader *l){ - ListNode *tmp = (ListNode*)ctl_malloc(getNodeSize(l)); - tmp->head = l; - tmp->next = NULL; - tmp->prev = l->data.next; - l->data.next->next = tmp; - l->data.next = tmp; - l->count++; -} -static void addNodeFront(ListHeader *l){ - ListNode *tmp = (ListNode*)ctl_malloc(getNodeSize(l)); - tmp->head = l; - tmp->prev = NULL; - tmp->next = l->data.prev; - l->data.prev->prev = tmp; - l->data.prev = tmp; - l->count++; -} +/******************** private functions *******************/ +#define addNode(l) \ + do{\ + ListNode *tzzzmp = (ListNode*)ctl_malloc(getNodeSize(l));\ + tzzzmp->head = (l);\ + tzzzmp->prev = NULL;\ + tzzzmp->next = NULL;\ + (l)->count = 1;\ + (l)->data.prev = tzzzmp;\ + (l)->data.next = tzzzmp;\ + }while(0) +#define addNodeBack(l) \ + do{\ + ListNode *tzzzmp = (ListNode*)ctl_malloc(getNodeSize(l));\ + tzzzmp->head = (l);\ + tzzzmp->next = NULL;\ + tzzzmp->prev = (l)->data.next;\ + (l)->data.next->next = tzzzmp;\ + (l)->data.next = tzzzmp;\ + (l)->count++;\ + }while(0) +#define addNodeFront(l) \ + do{\ + ListNode *tzzzmp = (ListNode*)ctl_malloc(getNodeSize(l));\ + tzzzmp->head = (l);\ + tzzzmp->prev = NULL;\ + tzzzmp->next = (l)->data.prev;\ + (l)->data.prev->prev = tzzzmp;\ + (l)->data.prev = tzzzmp;\ + (l)->count++;\ + }while(0) +#define delNode(l) \ + do{\ + ListNode*tzzzmp = (l)->data.prev;\ + free(tzzzmp);\ + (l)->data.prev = NULL;\ + (l)->data.next = NULL;\ + (l)->count = 0;\ + }while(0) +#define delNodeFront(l) \ + do{\ + ListNode *tzzzmp = (l)->data.prev;\ + (l)->data.prev = (l)->data.prev->next;\ + (l)->data.prev->prev = NULL;\ + free(tzzzmp);\ + (l)->count--;\ + }while(0) +#define delNodeBack(l) \ + do{\ + ListNode *tzzzmp = (l)->data.next;\ + (l)->data.next = (l)->data.next->prev;\ + (l)->data.next->next = NULL;\ + free(tzzzmp);\ + (l)->count--;\ + }while(0) +#define nodeConnect(a,b) \ + do{\ + if((a) != NULL){\ + (a)->next = (b);\ + }\ + if((b) != NULL){\ + (b)->prev = (a);\ + }\ + }while(0) /***************** initalize & destructure ****************/ pvoid ctl_list_initX(ppvoid l, size_t size, uint count){ @@ -59,25 +96,25 @@ pvoid ctl_list_initX(ppvoid l, size_t size, uint count){ tmp->data.head = tmp; tmp->data.prev = NULL; tmp->data.next = NULL; + pvoid ret; if(count > 0){ - addNode0(tmp); + addNode(tmp); int i; - for(i = 1; i < count; i++) + for(i = 1; i < count; i++){ addNodeBack(tmp); - if(l != NULL){ - l = tmp->data.prev->buf; } - return tmp->data.prev->buf; + ret = tmp->data.prev->buf; }else{ - if(l != NULL){ - l = tmp->data.buf; - } - return tmp->data.buf; + ret = tmp->data.buf; } + if(l != NULL){ + l = ret; + } + return ret; } pvoid ctl_list_freeX(ppvoid l){ - ListHead* tmp = getHeader(*l); + ListHeader* tmp = getHeader(*l); while(l->data.prev != NULL){ ListNode *ntmp = l->data.prev; l->data.prev = l->data.prev->next; @@ -109,37 +146,215 @@ pvoid ctl_list_getLastX(ppcvoid l){ } /**************** about set??? methods ********************/ -int ctl_list_setSizeX (ppvoid l, uint count){ +int ctl_list_setSizeX(ppvoid l, uint count){ ListHeader *tmp = getHeader(*l); - if(tmp->count > count){ - int i, ii = tmp->count - ctl_max(count, 1); - for(i = 0; i < ii; i++){ - + if(tmp->count > count){ // decrease + while(tmp->count > ctl_max(count, 1)){ + delNodeBack(tmp); + } + if(count == 0){ + delNode(tmp); + } + }else if(tmp->count < count){ // incrase + if(tmp->count == 0){ + addNode(tmp); + } + while(tmp->count < count){ + addNodeBack(tmp); } } + return tmp->count; +} +pvoid ctl_list_setFrontX(ppvoid l, pcvoid data){ + ListHeader *tmp = getHeader(*l); + memcpy(tmp->data.prev->buf, data, sizeof(tmp->size)); + return tmp->data.prev->buf; +} +pvoid ctl_list_setBackX(ppvoid l, pcvoid data){ + ListHeader *tmp = getHeader(*l); + memcpy(tmp->data.next->buf, data, sizeof(tmp->size)); + return tmp->data.next->buf; } -pvoid ctl_list_setFrontX(ppvoid l, pcvoid data); -pvoid ctl_list_setBackX (ppvoid l, pcvoid data); -int ctl_list_addFrontX(ppvoid l, pcvoid data); -int ctl_list_delFrontX(ppvoid l, pcvoid data); -int ctl_list_addBackX (ppvoid l, pcvoid data); -int ctl_list_delBackX (ppvoid l, pcvoid data); +/**************** about add/del front/back ****************/ +int ctl_list_addFrontX(ppvoid l, pcvoid data){ + ListHeader *tmp = getHeader(*l); + if(tmp->count == 0){ + addNode(tmp); + }else{ + addNodeFront(tmp); + } + ctl_list_setFrontX(l, data); + return tmp->count; +} +int ctl_list_delFrontX(ppvoid l){ + ListHead *tmp = getHeader(*l); + if(tmp->count == 1){ + delNode(tmp); + }else{ + delNodeFront(tmp); + } + return tmp->count; +} +int ctl_list_addBackX(ppvoid l, pcvoid data){ + ListHeader *tmp = getHeader(*l); + if(tmp->count == 0){ + addNode(tmp); + }else{ + addNodeBack(tmp); + } + ctl_list_setBackX(l, data); + return tmp->count; +} +int ctl_list_delBackX(ppvoid l){ + ListHead *tmp = getHeader(*l); + if(tmp->count == 1){ + delNode(tmp); + }else{ + delNodeBack(tmp); + } + return tmp->count; +} -int ctl_list_catX (ppvoid l, ppcvoid l2); -pvoid ctl_list_copyX (ppvoid l, ppcvoid l2); -int ctl_list_replaceX(ppvoid i1, uint ct1, ppcvoid j1, int ct2); -void ctl_list_swapX (ppvoid i1, ppvoid i2, ppvoid j1, ppvoid j2); +/************** about list's special methods **************/ +int ctl_list_rmX(ppvoid l, ppvoid i1, ppvoid i2){ + ListHeader *tmp = getHeader(*l ); + ListNode* n1 = getNode (*i1); + ListNode* n2 = getNode (*i2); + nodeConnect(n1->prev, n2); + if(tmp->data.prev == n1){ + tmp->data.prev = n2; + } + if(n2 == NULL){ + tmp->data.next = n1->prev; + } + int ret = 0; + while(n1 != n2){ + ListNode* ntmp = n1; + n1 = n1->next; + free(ntmp); + ret++; + } + tmp->count -= ret; + return ret; +} +pvoid ctl_list_copyX(ppvoid l, ppvoid i1, ppvoid i2, ppvoid out){ + ListHeader* tmp = getHeader(*l); + ListHeader* tmp2 = ctl_list_init(NULL, tmp->size, 0); + ListNode* n1 = getNode(*i1); + ListNode* n2 = getNode(*i2); + while(n1 != n2){ + ctl_list_addBack(tmp2->data.buf, n1->buf); + n1 = n1->next; + tmp2->count++; + } + if(out != NULL){ + *out = tmp2->data.buf; + } + return tmp2->data.buf; +} +pvoid ctl_list_moveX(ppvoid l, ppvoid i1, ppvoid i2, ppvoid out){ + ListHeader* tmp = getHeader(*l); + ListHeader* tmp2 = ctl_list_init(NULL, tmp->size, 0); + ListNode* n1 = getNode(*i1); + ListNode* n2 = getNode(*i2); + tmp2->data.prev = n1; + tmp2->cata.next = (n2 == NULL ? tmp->data.next : n2->prev); + nodeConnect(n1->prev, n2); + if(tmp->data.prev == n1){ + tmp->data.prev = n2; + } + if(n2 == NULL){ + tmp->data.next = n1->prev; + } + while(n1 != n2){ + n1 = n1->next; + tmp->count--; + tmp2->count++; + } + if(tmp2->count == 0){ + tmp2->data.prev = NULL; + tmp2->data.next = NULL; + }else{ + tmp2->data.prev->prev = NULL; + tmp2->data.next->next = NULL; + } + if(out != NULL){ + *out = tm2->data.buf; + } + return tmp2->data.buf; +} +int ctl_list_swapX(ppvoid l1, ppvoid i1, ppvoid i2, + ppvoid l2, ppvoid j1, ppvoid j2){ + ListHeader* h1 = getHeader(*l1); + ListHeader* h2 = getHeader(*l2); + ListNode* ni1 = getNode(*i1),* ni1p; + ListNode* ni2 = getNode(*i2),* ni2p; + ListNode* nj1 = getNode(*j1),* nj1p; + ListNode* nj2 = getNode(*j2),* nj2p; + ni1p = ni1->prev; + ni2p = (ni2 == NULL ? getHeader(*l1)->data.next : ni2->prev); + nj1p = nj1->prev; + nj2p = (nj2 == NULL ? getHeader(*l2)->data.next : nj2->prev); + int count1 = 0, count2 = 0; + if(ni1 == h1->data.prev) h1->data.prev = nj1; + if(nj1 == h2->data.prev) h2->data.prev = ni1; + if(ni2 == NULL) h1->data.next = nj2p; + if(nj2 == NULL) h2->data.next = ni2p; + ListNode* nii; + for(nii = ni1; nii != ni2; nii = nii->next) count1++; + for(nii = nj1; nii != nj2; nii = nii->next) count2++; + nodeConnect(ni1p, nj1); + nodeConnect(nj1p, ni1); + nodeConnect(ni2p, nj2); + nodeConnect(nj2p, ni2); + h1->size += (count2 - count1); + h2->size += (count1 - count2); + return count1; +} -pcvoid ctl_list_iterGetEntryX(ppcvoid i); -pvoid ctl_list_iterGetNextX (ppcvoid i); -pvoid ctl_list_iterGetPrevX (ppcvoid i); +/******************** about iterator **********************/ +pcvoid ctl_list_iterGetEntryX(ppcvoid i){ + return *i; +} +pvoid ctl_list_iterGetNextX(ppcvoid i){ + return getNode(*i)->next->buf; +} +pvoid ctl_list_iterGetPrevX(ppcvoid i){ + return getNode(*i)->prev->buf; +} -pvoid ctl_list_iterSetEntryX(ppvoid i, pcvoid *data); +pvoid ctl_list_iterSetEntryX(ppvoid i, pcvoid *data){ + memcpy(getNode(*i)->buf, data, getNode(*i)->head->size); + return getNode(*i)->buf; +} -pvoid ctl_list_iterGoNextX(ppcvoid i); -pvoid ctl_list_iterGoPrevX(ppcvoid i); +pvoid ctl_list_iterGoNextX(ppvoid i){ + *i = getNode(*i)->next->buf; + return *i; +} +pvoid ctl_list_iterGoPrevX(ppvoid i){ + *i = getNode(*i)->prev->buf; + return *i; +} -pvoid ctl_list_iterDelX (ppvoid i); -pvoid ctl_list_iterDelPrevX(ppvoid i); -pvoid ctl_list_iterDelNextX(ppvoid i); +pvoid ctl_list_iterDelX(ppvoid i){ + ListNode *n = getNode(*i); + nodeConnect(n->prev, n->next); + if(n == n->head->data.prev){ + n->head->data.prev = n->next; + } + if(n == n->head->data.next){ + n->head->data.next = n->prev; + } + n->head->count--; + return n->next->buf; +} +pvoid ctl_list_iterDelPrevX(ppvoid i){ + ctl_list_iterDelX(getNode(*i)->prev->buf); + return *i; +} +pvoid ctl_list_iterDelNextX(ppvoid i){ + ctl_list_iterDelX(getNode(*i)->next->buf); + return *i; +} @@ -0,0 +1,155 @@ +#include <stdio.h> + +#include "include/list.h" + +void print(double *x){ + double *a = ctl_list_getBegin(&x); + const double *b = ctl_list_getEnd (&x); + printf("size = %d(%d): ", ctl_list_getSize(&x), ctl_list_getEntrySize(&x)); + for( ; a != b; a = ctl_list_iterGetNext(a)){ + printf("%.1f ", *a); + } + printf("\n"); + printf("size = %d(%d): ", ctl_list_getSize(&x), ctl_list_getEntrySize(&x)); + for(a = ctl_list_getBegin(&x); a != x; a = ctl_list_iterGetNext(a)){ + printf("%.1f ", *a); + } + printf("\n"); +} + +int main(){ + double *l, tmp; + ctl_list_init(&l, sizeof(double), 0); + print(l); + tmp = 123; printf("add %f\n", tmp); ctl_list_addFront(&l, &tmp); + tmp = 133; printf("add %f\n", tmp); ctl_list_addFront(&l, &tmp); + tmp = 143; printf("add %f\n", tmp); ctl_list_addFront(&l, &tmp); + tmp = 153; printf("add %f\n", tmp); ctl_list_addFront(&l, &tmp); + tmp = 163; printf("add %f\n", tmp); ctl_list_addFront(&l, &tmp); + tmp = 23; printf("add %f\n", tmp); ctl_list_addBack(&l, &tmp); + tmp = 33; printf("add %f\n", tmp); ctl_list_addBack(&l, &tmp); + tmp = 43; printf("add %f\n", tmp); ctl_list_addBack(&l, &tmp); + tmp = 53; printf("add %f\n", tmp); ctl_list_addBack(&l, &tmp); + tmp = 63; printf("add %f\n", tmp); ctl_list_addBack(&l, &tmp); + print(l); + ctl_list_delFront(&l); + printf("<front, back> = <%.1f, %.1f>\n", + *(double*)ctl_list_getFront(&l), + *(double*)ctl_list_getBack(&l)); + ctl_list_delFront(&l); + printf("<front, back> = <%.1f, %.1f>\n", + *(double*)ctl_list_getFront(&l), + *(double*)ctl_list_getBack(&l)); + ctl_list_delBack(&l); + printf("<front, back> = <%.1f, %.1f>\n", + *(double*)ctl_list_getFront(&l), + *(double*)ctl_list_getBack(&l)); + print(l); + ctl_list_setSize(&l, 20); + printf("<front, back> = <%.1f, %.1f>\n", + *(double*)ctl_list_getFront(&l), + *(double*)ctl_list_getBack(&l)); + print(l); + ctl_list_setSize(&l, 1); + print(l); + ctl_list_setSize(&l, 3); + print(l); + ctl_list_setSize(&l, 0); + print(l); + int i; + double tmpd; + for(i = 0; i < 20; i++){ + tmpd = i; + ctl_list_addBack(&l, &(tmpd)); + } + print(l); + ctl_list_rm(&l, + ctl_list_iterGetNext(ctl_list_iterGetNext(ctl_list_getBegin(&l))), + ctl_list_iterGetPrev(ctl_list_iterGetPrev(ctl_list_iterGetPrev(ctl_list_iterGetPrev(ctl_list_iterGetPrev(ctl_list_getEnd(&l))))))); + print(l); + double *a = ctl_list_getBegin(&l), *b, *i1, *i2; + printf("entry = %.0f\n", *(double*)ctl_list_iterGetEntry(a)); + a = ctl_list_iterGetNext(a); + printf("entry = %.0f\n", *(double*)ctl_list_iterGetEntry(a)); + a = ctl_list_iterGetNext(a); + printf("entry = %.0f\n", *(double*)ctl_list_iterGetEntry(a)); + a = ctl_list_iterGetNext(a); + a = ctl_list_iterGetPrev(a); + a = ctl_list_iterGetPrev(a); + tmpd = 123; + ctl_list_iterSetEntry(a, &tmpd); + printf("entry = %.0f\n", *(double*)ctl_list_iterGetEntry(a)); + + + for(i = 0; i < 20; i++){ + tmpd = i; + ctl_list_addBack(&l, &(tmpd)); + } + print(l); + + i1 = ctl_list_getBegin(&l); + for(i = 0; i < 5; i++) i1 = ctl_list_iterGetNext(i1); + for(i2 = i1, i = 0; i < 6; i++) i2 = ctl_list_iterGetNext(i2); + printf("copy!!\n"); + ctl_list_copy(&l, i1, i2, &b); + print(l); + print(b); + ctl_list_rm(&l, i1, i2); + print(l); + print(b); + ctl_list_free(&b); + a = ctl_list_getEnd(&l); + for(i = 0; i < 7; i++){ + a = ctl_list_iterGetPrev(a); + printf("double %.1f\n", *a); + } + + ctl_list_move(&l,a,ctl_list_iterGetPrev(ctl_list_getEnd(&l)),&b); + print(l); + print(b); + + { + + double *i1, *i2, *j1, *j2; + i2 = i1 = ctl_list_getBegin(&l); + for(i = 0; i < 5; i++) + i2 = ctl_list_iterGetNext(i2); + j1 = j2 = ctl_list_getBegin(&b); + for(i = 0; i < 3; i++) + j2 = ctl_list_iterGetNext(j2); + ctl_list_swap(&l,i1,i2,&b,j1,j2); + print(l); + print(b); + } + + ctl_list_free(&l); + ctl_list_free(&b); + return 0; + + + + + + a = ctl_list_iterGetNext(a); + printf("a = %.1f\n", *a); + a = ctl_list_iterDel(a); + print(l); + a = ctl_list_iterGetNext(a); + printf("a = %.1f\n", *a); + a = ctl_list_iterDelNext(a); + print(l); + printf("a = %.1f\n", *a); + a = ctl_list_iterDelNext(a); + print(l); + printf("a = %.1f\n", *a); + a = ctl_list_iterDelPrev(a); + a = ctl_list_iterDel(a); + a = ctl_list_iterGetPrev(a); + a = ctl_list_iterDelPrev(a); + a = ctl_list_iterDel(a); + print(l); + + printf("go free!\n"); + ctl_list_free(&l); + return 0; +} |