Exemple #1
0
int main()
{
    LinkList La;
    InitList_L(La);
    ElemType e;
    printf("Assigment for La:\n");
    CreateList_L(La,5);
    printf("The elements in La:\n");
    ListTraverse_L(La,Display_L);
    ListDelete_L(La, 2, e);
    printf("We have deleted the 2th element in La:\n");
    ListTraverse_L(La,Display_L);
    ListInsert_L(La, 2, e);
    printf("Put the element deleted in the proier statement in 2th:\n");
    ListTraverse_L(La,Display_L);
    LinkList Lb;
    InitList_L(Lb);
    printf("Assigment for another LinkList Lb:\n");
    CreateList_L(Lb,5);
    printf("The elements in Lb:\n");
    ListTraverse_L(Lb,Display_L);
    LinkList Lc;
    InitList_L(Lc);
    MergeList_L(La, Lb, Lc);
    printf("After merging La and Lb:\n");
    ListTraverse_L(Lc,Display_L);
    printf("The number of elements in Lb: %d\n",ListLength_L(Lc));
    Destroy_L(La);
    Destroy_L(Lb);
    Destroy_L(Lc);
    return 0;
}
void Convert(LinkList first,LinkList &result) {
	ElemType elem;
	first = first->next;
	while (first!=NULL)
	{
		elem = first->data;
		ListInsert_L(result,1,elem);
		first = first->next;//总是插入第一个
	}
}
void main(){
LinkList L;
ElemType e;
int i,n;
printf("(一)创建一个带头节点的空的单链表\n");
CreateList_L(L);
 printf("将学生的信息输入到顺序表!\n");
   printf("请输入学生人数!\n");
	scanf("%d",&n);
printf("(二)依次采用尾插法插入元素!\n");
  for(i=1;i<=n;i++){
	   printf("请输入第%d个学生的信息:姓名,学号,分数\n",i);
		   scanf("%s%d%d",e.name,&e.num,&e.score);
	    ListInsert_L(L,i,e);}
printf("(三)这%d个学生的信息为:\n",n);
printf("姓名        学号     分数\n");
for(i=1;i<=n;i++)
{GetElem_L(L,i,e);
printf("%-10s %4d %4d\n",e.name,e.num,e.score);
}
printf("(四)顺序表L为%s\n",ListEmpty_L(L)?"空":"非空");
printf("(五)顺序表的长度=%d\n",ListLength(L));
printf("(六)请输入要删除元素的位置\n");
scanf("%d",&i);
ListDelete_L(L,i,e);
printf("删除的这个元素为:\n");
printf("%-10s %4d %4d\n",e.name,e.num,e.score);
printf("(七)请输入要插入元素的位置及元素内容\n");
scanf("%d%s%d%d",&i,e.name,&e.num,&e.score);
ListInsert_L(L,i,e);
printf("此时顺序表L中元素为:\n");
for(i=1;i<=ListLength(L);i++){
	GetElem_L(L,i,e);
	printf("%-10s %4d %4d\n",e.name,e.num,e.score);
}

printf("(八)释放顺序表\n");
DestroyList_L(L);

}
Exemple #4
0
int main(int argc, char *argv[])
{
    LinkList L;
    CreateList_L(&L);
    int i;
    for(i = 1; i < 10; i++)
    {
        ListInsert_L(L, i, i);
    }
    int e;
    ListDelete_L(L, 5, &e);
    ListPrint_L(L);

    return 0;
}
Exemple #5
0
//对线性表的各个功能函数做测试
void ListTest()
{
	LinkList La,Lb,Lc;
	int i;
	ElemType temp;

	LinkList p;
	int j;

	CreatList_L( La, 5);
	printf("the list is:");
	for ( i=1; i<6; i++ )
	{
		GetElem_L( La, i, temp );
		printf("%d ",temp);
	}

	if ( ListInsert_L( La, 3,77) )
	{
		printf("\nthe insert list is:");
		for ( i=1; i<7; i++ )
		{
			GetElem_L( La, i, temp );
			printf("%d ",temp);
		}
	}
	
	if ( ListDelet_L( La, 3,temp) )
	{
		printf("\nthe delet list is:");
		for ( i=1; i<6; i++ )
		{
			GetElem_L( La, i, temp );
			printf("%d ",temp);
		}
	}

	
	CreatList_L( Lb, 5);
	printf("\n the list a is:");
	for ( i=1; i<6; i++ )
	{
		GetElem_L( La, i, temp );
		printf("%d ",temp);
	}
	printf("\n the list b is:");
	for ( i=1; i<6; i++ )
	{
		GetElem_L( Lb, i, temp );
		printf("%d ",temp);
	}
	MergeList_L( La, Lb, Lc);
	printf("\n the list c is:");
	for ( i=1; i<11; i++ )
	{
		GetElem_L( Lc, i, temp );
		printf("%d ",temp);
	}


}