Exemple #1
0
/********************************************************************
	Method:    InsertTest
	Parameter:
	Returns:

	Purpose:   插入测试

*********************************************************************/
bool InsertTest(LinkList &L)
{
    ElemType e;
    e.data = 6;
    InsertElem(L, e, 4);	//	插入到最后一个位置

    e.data = 7;
    InsertElem(L, e, 1);	//	插入到第一个位置

    e.data = 8;
    InsertElem(L, e, 2);	//	插入到中间某一位置

    TraverseList(L, visit);

    /////////////////////////////////////////
    /*
    LinkList L1;
    CreateListByHead(L1, 0);

    e.data = 1;
    InsertElem(L1, e, 1);	//	在空链表中插入元素

    TraverseList(L1);
    */

    return true;
}
Exemple #2
0
int main(){
	List L;
	CreateList(L);
	InsertElem(L, 1, 100);
	InsertElem(L, 2, 200);
	InsertElem(L, 3, 300);
	InsertElem(L, 6, 500);
	PrintList(L);
	backPrintList(L);
}
Exemple #3
0
int		main(void){
	LS n;
	int i = 0;
	int e = 3;
	printf("%d\n",EmptyList(&n));
	while(scanf("%d",&(n.data[i])))
		i++;
	n.length = i;
	InsertElem(&n,2,0);
	for (int i=0;i<n.length;i++){
		printf("%d\n",n.data[i]);
	}
	printf("%d\n",EmptyList(&n));
	RemoveElem(&n,2,&e);
	for (int i=0;i<n.length;i++){
		printf("%d\n",n.data[i]);
	}
	printf("%d\n",e);
	printf("%d\n",EmptyList(&n));

	GetElem(&n,2,&e);
	for (int i=0;i<n.length;i++){
		printf("%d\n",n.data[i]);
	}
	printf("%d\n",e);
	printf("%d\n",EmptyList(&n));

	printf("%d\n",LoctElem(&n,e));

	ClearList(&n);
	printf("%d\n",EmptyList(&n));
	getchar();
}
Exemple #4
0
void main(void)
{
	Sqlist l;
	int i;
	initSqlist(&l);
	for (i=0; i<15; i++)
	{
		InsertElem(&l,i+1,i+1);
	}

	printf("\nThe content of the list is \n");

	for (i =0; i<l.length; i++)
	{
		printf("%d ",l.elem[i]);
	}

	DeleElem(&l,5);

	printf("\nDelete the fifth element\n");

	for (i=0; i<l.length; i++)
	{
		printf("%d ",l.elem[i]);
	}

	return ;
}
int main () {
	SqList sl = {{1, 2, 3, 4, 5}, 5};
	ElemType e;
	int index = 2;
	int result = GetElem(sl, index, &e);
	if (result) {
		printf("%i\n", e);
	} else {
		printf("Error: cannot found the %i index in SqList\n", index);
	}

	ElemType newInsertElemType = 6;
	int newIndex = 2;
	result = InsertElem(&sl, newIndex, newInsertElemType);
	GetElem(sl, newIndex, &newInsertElemType);

	if (result) {
		printf("The element[%i]: %i inserted successful, length change to: %i\n", newIndex, newInsertElemType, sl.length);
		for (int i = 0; i < sl.length; i++) {
			printf("The index:%i, value is:%i\n", i, sl.data[i]);
		}
	}

	result = DeleteElem(&sl, newIndex);
	if (result) {
		printf("The Sqlist length is: %i\n", sl.length);
		for (int i = 0; i < sl.length; i++) {
			printf("The index:%i, value is:%i\n", i, sl.data[i]);
		}
	}

}
int main(int argc, const char * argv[])
{
    Sqlist l;
    int i;
    initSqlist(&l);
    for (i = 0 ; i < 15 ; i++)
    {
        InsertElem(&l, i + 1, i + 1);
    }
    printf("\nThe content of the list is \n");
    for (i = 0 ; i < l.length ; i++)
        printf("%d  ",l.elem[i]);
    DelElem(&l, 5);
    printf("\nDelete the fifth element\n");
    for (i = 0 ; i < l.length ; i++)
        printf("%d  ",l.elem[i]);
    printf("\nover\n");
    return 0;
}