数据结构C语言版 单链表源代码Word格式.docx

上传人:b****2 文档编号:4101756 上传时间:2023-05-02 格式:DOCX 页数:8 大小:15.08KB
下载 相关 举报
数据结构C语言版 单链表源代码Word格式.docx_第1页
第1页 / 共8页
数据结构C语言版 单链表源代码Word格式.docx_第2页
第2页 / 共8页
数据结构C语言版 单链表源代码Word格式.docx_第3页
第3页 / 共8页
数据结构C语言版 单链表源代码Word格式.docx_第4页
第4页 / 共8页
数据结构C语言版 单链表源代码Word格式.docx_第5页
第5页 / 共8页
数据结构C语言版 单链表源代码Word格式.docx_第6页
第6页 / 共8页
数据结构C语言版 单链表源代码Word格式.docx_第7页
第7页 / 共8页
数据结构C语言版 单链表源代码Word格式.docx_第8页
第8页 / 共8页
亲,该文档总共8页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

数据结构C语言版 单链表源代码Word格式.docx

《数据结构C语言版 单链表源代码Word格式.docx》由会员分享,可在线阅读,更多相关《数据结构C语言版 单链表源代码Word格式.docx(8页珍藏版)》请在冰点文库上搜索。

数据结构C语言版 单链表源代码Word格式.docx

voiddele(structLNode**p,inti);

voiddisplay(structLNode**p);

intlocate(structLNode**p,ElemTypex);

voidmain()

structLNode*head,*q;

/*定义静态变量*/

intselect,x1,x2,x3,x4;

inti,n;

intm,g;

chare,y;

setnull(&

head);

/*建设链表并设置为空表*/

printf("

请输入数据长度:

"

);

scanf("

%d"

&

n);

for(i=1;

i<

=n;

i++)

{

printf("

将数据插入到单链表中:

scanf("

y);

insert(&

head,y,i);

}/*插入数据到链表*/

display(&

/*显示链表所有数据*/

select1求长度length()\n"

select2取结点get()\n"

select3求值查找locate()\n"

select4删除结点delete()\n"

select0退出\n"

inputyourselect:

select);

while(select!

=0)

{switch(select)

case1:

{

x1=length(&

printf("

输出单链表的长度%d"

x1);

display(&

}break;

case2:

请输入要取得结点:

scanf("

m);

x2=get(&

head,m);

x2);

case3:

{

printf("

请输入要查找的数据:

e);

x3=locate(&

head,e);

x3);

case4:

请输入要删除的结点:

g);

dele(&

head,g);

}

printf("

}

}

voidsetnull(structLNode**p)

*p=null;

intlength(structLNode**p)

intn=0;

structLNode*q=*p;

while(q!

=null)

n++;

q=q->

next;

return(n);

ElemTypeget(structLNode**p,inti)

intj=1;

structLNode*q=*p;

while(j<

i&

&

q!

j++;

if(q!

return(q->

data);

else

{printf("

位置参数不正确!

\n"

return0;

intlocate(structLNode**p,ElemTypex)

while(q!

=null&

q->

data!

=x)

if(q==null)

return(-1);

return(n+1);

voidinsert(structLNode**p,ElemTypex,inti)

structLNode*s,*q;

s=(structLNode*)malloc(sizeof(structLNode));

s->

data=x;

q=*p;

if(i==1)

s->

next=q;

*p=s;

while(j<

i-1&

next!

q=q->

j++;

}

if(j==i-1)

s->

next=q->

q->

next=s;

else

}

voiddele(structLNode**p,inti)

structLNode*q=*p,*t;

t=q;

*p=q->

if(q->

j==i-1)

t=q->

next=t->

if(t!

=null)

free(t);

voiddisplay(structLNode**p)

{

structLNode*q;

单链表显示:

链表为空!

"

elseif(q->

next==null)

%d\n"

q->

while(q->

%d->

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 中考

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2