#include< stdio.h >
#include"link.h"
void main()
{
LNode *list;
LNode *list1;
LNode *list2;
LNode head;
LNode head1;
LNode head2;
ElemType e;
int count;
list = &head;
list1 = &head1;
list2 = &head2;
//创建有n个元素的链表,逆序输入n个元素的值,建立带有头结点的单链线性表
CreateList_L( &head, 5);
Print_L( list );
CreateList_L( &head1, 5);
Print_L( list1 );
//向链表中插入和删除元素,测试各种可能的情况
printf("***********插入和删除第i个元素且i <= 0的情况**********\n");
if( ListInsret_L( list, 0, 0 ) )
Print_L( list );
if( ListDelete_L( list, 0, &e ) ){
printf("the delete element is %d\n", e );
Print_L( list );
}
printf("***************插入和删除第1个元素的情况**************\n");
if( ListInsret_L( list, 1, 1 ) )
Print_L( list );
if( ListDelete_L( list, 1, &e ) ){
printf("the delete element is %d\n", e );
Print_L( list );
}
printf("****插入和删除既不是第一个也不是最后一个元素的情况****\n");
if( ListInsret_L( list, 3, 3 ) )
Print_L( list );
if( ListDelete_L( list, 3, &e ) ){
printf("the delete element is %d\n", e );
Print_L( list );
}
printf("*************插入和删除最后一个元素的情况*************\n");
if( ListInsret_L( list, 6, 6 ) )
Print_L( list );
if( ListDelete_L( list, 6, &e ) ){
printf("the delete element is %d\n", e );
Print_L( list );
}
printf("***插入和删除的第i个元素超出链表的元素个数时的情况***\n");
if( ListInsret_L( list, 8, 8 ) )
Print_L( list );
if( ListDelete_L( list, 8, &e ) ){
printf("the delete element is %d\n", e );
Print_L( list );
}
//链表元素个数
printf("**********输出链表元素个数***************************\n");
count = CountList( list );
printf( "there is %d elements in the list\n", count );
//获得链表的第i个元素
printf("**************获得链表的第i个元素*******************\n");
if( GetElem_L( list, 0, &e ) )
printf(" e = %d\n", e );
else
printf("the element doesn't exist\n");
if( GetElem_L( list, 1, &e ) )
printf(" e = %d\n", e );
else
printf("the element doesn't exist\n");
if( GetElem_L( list, 5, &e ) )
printf(" e = %d\n", e );
else
printf("the element doesn't exist\n");
if( GetElem_L( list, 8, &e ) )
printf(" e = %d\n", e );
else
printf("the element doesn't exist\n");
//判断元素e是否位于链表中
printf("****************判断元素e是否在链表中****************\n");
e = 16;
count = LocateElem_L( list, e );
if( count )
printf("%d is the %d element of the link list\n", e, count );
else
printf("%d is not in the link list\n", e );
e = 45;
count = LocateElem_L( list, e );
if( count )
printf("%d is the %d element of the link list\n", e, count );
else
printf("%d is not in the link list\n", e );
//对链表进行排序:按递减序列排序,合并两个链表,按递减排列,合并后的结果位于第三个链表
printf("****************对第一个链表排序**************\n");
list = Reserve( list );
Print_L( list );
printf("****************对第二个链表排序**************\n");
list1 = Reserve( list1 );
Print_L( list1);
printf("****************合并两个链表******************\n");
list2->next = NULL;
MergeList( list, list1, list2 );
Print_L( list2 );
//合并两个链表,按递减排列,将链表之间的关系重新组织,不需要复制到新的链表中
printf("***********重新组织关系合并两个链表***********\n");
MergeList_L( list, list1 );
Print_L( list );
Print_L( list1 );
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
.rar (15个子文件)
单链表
单链表.dsw 537B
link.h 5KB
main.c 3KB
单链表.plg 1KB
单链表.opt 49KB
单链表.ncb 49KB
单链表.dsp 4KB
Debug
单链表.opt 43KB
vc60.idb 33KB
main.obj 19KB
单链表.pdb 449KB
单链表.exe 184KB
单链表.pch 201KB
单链表.ilk 251KB
vc60.pdb 52KB
共 15 条
- 1
资源评论
JessicaWind
- 粉丝: 71
- 资源: 77
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功