int main(int argc, const char * argv[]) { Teacher teacher1 = {11, "Mr Wang", 'M'}; Teacher teacher2 = {22, "Mr Jiang", 'M'}; Teacher teacher3 = {33, "Mr Huang", 'M'}; Teacher teacher4 = {44, "Mr Si", 'M'}; Teacher teacher5 = {55, "Mr Wu", 'M'}; SeqList *list = SeqList_Create(100); if (!list) return -1; //Insert SeqList_Insert(list, &teacher1, 0); SeqList_Insert(list, &teacher2, 0); SeqList_Insert(list, &teacher3, 0); SeqList_Insert(list, &teacher4, 0); SeqList_Insert(list, &teacher5, 0); //print for (int i = 0; i < SeqList_Length(list); i ++) { Teacher *teacher = (Teacher*)SeqList_Get(list, i); printf("ListNode %d name:%s\n", i, teacher->name); } //delete SeqList_Delete(list, 3); SeqList_Delete(list, 5); //print for (int i = 0; i < SeqList_Length(list); i ++) { Teacher *teacher = (Teacher*)SeqList_Get(list, i); printf("ListNode %d name:%s\n", i, teacher->name); } SeqList_Clear(list); SeqList_Destroy(list); return 0; }
int main() { int ret = 0, i = 0; SeqList* list = NULL; Teacher* tmp = NULL; Teacher t1, t2, t3; t1.age = 31; strcpy(t1.name, "tbf1"); t2.age = 32; strcpy(t2.name, "tbf2"); t3.age = 33; strcpy(t3.name, "tbf3"); list = SeqList_Create(10); SeqList_Insert(list, (SeqListNode *)&t1, 0); SeqList_Insert(list, (SeqListNode *)&t2, 0); SeqList_Insert(list, (SeqListNode *)&t3, 1); for(i = 0; i < SeqList_Length(list); i++) { tmp = (Teacher *)SeqList_Get(list, i); if(tmp != NULL) { printf("%s is %d\n", tmp->name, tmp->age); } } SeqList_Destroy(list); return 0; }
void thread_via_list(BTreeNode* root, SeqList* list) { if( (root != NULL) && (list != NULL) ) { SeqList_Insert(list, (SeqListNode*)root, SeqList_Length(list)); thread_via_list(root->left, list); thread_via_list(root->right, list); } }
int main(int argc, char *argv[]) { SeqList* list = SeqList_Create(SIZE); int a[SIZE] = {0}; int i = 0; int key = 0; int index = 0; srand((unsigned int)time(NULL)); for(i=0; i<SIZE; i++) { a[i] = rand() % 100; SeqList_Insert(list, (SeqListNode*)(rand() % 100), i); } key = rand() % 100; printf("Static Search Demo\n"); printf("Key: %d\n", key); printf("Array: \n"); print_array(a, SIZE); index = static_search(a, SIZE, key); if( index >= 0 ) { printf("Success: a[%d] = %d\n", index, a[index]); } else { printf("Failed!\n"); } printf("Dynamic Search Demo\n"); printf("Key: %d\n", key); printf("List: \n"); print_list(list); index = dynamic_search(list, key); if( index >= 0 ) { printf("Success: list[%d] = %d\n", index, key); } else { printf("Failed!\n"); } print_list(list); return 0; }
int main (void) { SeqList* list; int capacity = 10; int array[10] = {1,2,3,4,5,6,7,8,9,10}; int i = 0; list = SeqList_Create(capacity); printf("list was empty,length=%d\n",SeqList_Length(list)); for (i=0; i<10; i++) { SeqList_Insert(list, &array[i], 0); printf("Insert node,length=%d\n",SeqList_Length(list)); } SeqListNode* delnode = SeqList_Delete(list, 4); printf("--------del node elem=%d\n",*(int*)delnode); SeqList_print(list); SeqList_clear(list); printf("list was empty,length=%d\n",SeqList_Length(list)); SeqList_Destory(list); }
int SeqQueue_Append(SeqQueue* queue, void* item) // O(1) { return SeqList_Insert(queue, item, SeqList_Length(queue)); }