Exemple #1
0
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;
}
Exemple #2
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;
}
Exemple #3
0
int main(int argc, char *argv[])
{
    BTree* tree = BTree_Create();
    BTreeNode* current = NULL;
    BTreeNode* p = NULL;
    SeqList* list = NULL;
    int i = 0;
    
    struct Node n1 = {{NULL, NULL}, 'A'};
    struct Node n2 = {{NULL, NULL}, 'B'};
    struct Node n3 = {{NULL, NULL}, 'C'};
    struct Node n4 = {{NULL, NULL}, 'D'};
    struct Node n5 = {{NULL, NULL}, 'E'};
    struct Node n6 = {{NULL, NULL}, 'F'};
    
    BTree_Insert(tree, (BTreeNode*)&n1, 0, 0, 0);
    BTree_Insert(tree, (BTreeNode*)&n2, 0x00, 1, 0);
    BTree_Insert(tree, (BTreeNode*)&n3, 0x01, 1, 0);
    BTree_Insert(tree, (BTreeNode*)&n4, 0x00, 2, 0);
    BTree_Insert(tree, (BTreeNode*)&n5, 0x02, 2, 0);
    BTree_Insert(tree, (BTreeNode*)&n6, 0x02, 3, 0);
    
    printf("Full Tree: \n");
    
    BTree_Display(tree, printf_data, 4, '-');
    
    printf("Thread via List:\n");
    
    list = SeqList_Create(BTree_Count(tree));
    
    thread_via_list(BTree_Root(tree), list);
    
    for(i=0; i<SeqList_Length(list); i++)
    {
        printf("%c, ", ((struct Node*)SeqList_Get(list, i))->v);
    }
    
    printf("\n");
    
    printf("Thread via Left:\n");
    
    current = BTree_Root(tree);
    
    thread_via_left(current, &p);
    
    while( current != NULL )
    {
        printf("%c, ", ((struct Node*)current)->v);
        
        current = current->left;
    }
    
    printf("\n");
    
    BTree_Destroy(tree);
    
	return 0;
}
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);
}
SeqQueue* SeqQueue_Create(int capacity) // O(1)
{
    return SeqList_Create(capacity);
}