int main(int argc, char *argv[]) { LinkList *l=LinkListInit(); LinkList*m; int i=0; Value v1,v2,v3,v4,v5,v6; Value *temp; v1.data=1; v2.data=2; v3.data=3; v4.data=4; v5.data=5; printf("\n当前链表的长度为:%d\n",LinkListLength(l)); if(LinkListIsEmpty(l)==True) { printf("\n当前链表为空!\n"); } LinkListInsert(l,(LinkListNode*)&v1,0); LinkListInsert(l,(LinkListNode*)&v2,1); LinkListInsert(l,(LinkListNode*)&v3,2); LinkListInsert(l,(LinkListNode*)&v4,3); LinkListInsert(l,(LinkListNode*)&v5,4); printf("\n当前链表的长度为:%d\n",LinkListLength(l)); if(LinkListIsEmpty(l)==True) { printf("\n当前链表为空!\n"); } temp=(Value*)LinkListGet(l,0); printf("\n链表中第%d个结点数据域为:%d\n",0,temp->data); temp=(Value*)LinkListGet(l,1); printf("\n链表中第%d个结点数据域为:%d\n",1,temp->data); temp=(Value*)LinkListGet(l,2); printf("\n链表中第%d个结点数据域为:%d\n",2,temp->data); temp=(Value*)LinkListGet(l,3); printf("\n链表中第%d个结点数据域为:%d\n",3,temp->data); /* for(i=0;i<LinkListLength(l);i++) { temp=(Value*)LinkListGet(l,i); printf("\n链表中第%d个结点数据域为:%d\n",i,temp->data); }*/ LinkListDelete(l,2); printf("\n当前链表的长度为:%d\n",LinkListLength(l)); temp=(Value*)LinkListGet(l,2); printf("\n链表中第%d个结点数据域为:%d\n",2,temp->data); return 0; }
int main() { LinkList ll; LinkListInit(&ll, match, (void *)destory); for (int i=0; i<SIZE; i++) { a[i] = i; LinkListInsertNext(&ll, NULL, (void *)&a[i]); } printf("%d\n", LinkListSize(&ll)); void *tempData; LinkListNode *tempNode; int searchNumber = 5; if ( (tempNode = LinkListSearchByData(&ll, (void *)&searchNumber)) != NULL) { printf("%d\n", *(int *)tempNode->data); if ( (LinkListSearch(&ll, tempNode)) == SUCCESS) { printf("data->reflecting %d node in the linklit\n", *(int *)tempNode->data); printf("node->data %d will be modified!\n", searchNumber); searchNumber = 111111; tempData = &searchNumber; if ( (LinkListModify(&ll, tempNode, tempData)) == SUCCESS) { printf("the tempNode had been modified and i will get it by value\n"); if ( (tempNode = LinkListSearchByData(&ll, &searchNumber)) != NULL) { printf("the get data is %d\n", *(int *)tempNode->data); } }else { printf("node not be modified!\n"); } }else { printf("data->reflecting is not in the linklist\n"); } }else { printf("%d is not found\n", searchNumber); } searchNumber = -1; if ( (tempNode = LinkListSearchByData(&ll, (void *)&searchNumber)) != NULL) { printf("%d\n", *(int *)tempNode->data); if( (LinkListSearch(&ll, tempNode)) == SUCCESS) { printf("data->reflecting %d node in the linklit\n", *(int *)tempNode->data); }else { printf("data->reflecting is not in the linklist\n"); } }else { printf("%d is not found\n", searchNumber); } while (isLinkListEmpty(&ll) != SUCCESS) { LinkListRemoveNext(&ll, NULL, &tempData); printf("%d | ", *(int *)tempData); } printf("\n"); printf("%d\n", LinkListSize(&ll)); for(int i=0; i<SIZE; i++) { LinkListInsertNext(&ll, NULL, a+i); } printf("%d\n", LinkListSize(&ll)); /* while (LinkListRemoveNext(&ll, NULL, &tempData) == SUCCESS) { printf("[%d]=>{%d} | ", LinkListSize(&ll), *(int *)tempData); } printf("\n"); */ printf("destory linlist ll size::%d\n", LinkListSize(&ll)); LinkListDestory(&ll); printf("linklist ll had destoied!\n"); printf("%d\n", LinkListSize(&ll)); printf("%d\n", LinkListSize(&ll)); printf("%d\n", isLinkListHead(&ll, tempNode)); printf("%d\n", isLinkListTail(&ll, tempNode)); return 0; }