Example #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;
}
Example #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;
}
Example #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;
}
void print_list(SeqList* list)
{
    int i = 0;
    
    for(i=0; i<SeqList_Length(list); i++)
    {
        printf("%d, ", (int)SeqList_Get(list, i));
    }
    
    printf("\n");
}
Example #5
0
SeqListNode* SeqList_Delete(SeqList* list, int pos)
{
    TSeqList* sList  = (TSeqList*)list;
    SeqListNode* ret = SeqList_Get(list, pos);
    int i = 0;

    if (ret != NULL) {
        for (i=pos+1; i<sList->length; i++) {
            sList->node[i-1] = sList->node[i];
        }

        sList->length--;
    }

    return ret;
}
int dynamic_search(SeqList* list, int key)
{
    int ret = -1;
    int i = 0;
    
    for(i=0; i<SeqList_Length(list); i++)
    {
        if( (int)SeqList_Get(list, i) == key )
        {
            ret = i;
            
            SeqList_Delete(list, i);
            
            break;
        }
    }
    
    return ret;
}
void* SeqQueue_Header(SeqQueue* queue) // O(1) 
{
    return SeqList_Get(queue, 0);
}