软件上机报告源码段景山Word文档格式.docx

上传人:b****2 文档编号:15116528 上传时间:2022-10-27 格式:DOCX 页数:47 大小:239.42KB
下载 相关 举报
软件上机报告源码段景山Word文档格式.docx_第1页
第1页 / 共47页
软件上机报告源码段景山Word文档格式.docx_第2页
第2页 / 共47页
软件上机报告源码段景山Word文档格式.docx_第3页
第3页 / 共47页
软件上机报告源码段景山Word文档格式.docx_第4页
第4页 / 共47页
软件上机报告源码段景山Word文档格式.docx_第5页
第5页 / 共47页
点击查看更多>>
下载资源
资源描述

软件上机报告源码段景山Word文档格式.docx

《软件上机报告源码段景山Word文档格式.docx》由会员分享,可在线阅读,更多相关《软件上机报告源码段景山Word文档格式.docx(47页珍藏版)》请在冰豆网上搜索。

软件上机报告源码段景山Word文档格式.docx

i<

MAXNUM;

i++)

{

scanf("

%d"

&

elem);

if(elem==-1)break;

data[i]=elem;

length++;

}

}

voidshowlist(list_type*lp)

inti;

\nThese%drecordsare:

\n"

lp->

length);

if(lp->

length<

=0)

Nodata!

return;

lp->

length;

%d"

data[i]);

\nlengthofthelistis:

%d\n"

intinsertlist(list_type*lp,intnew_elem,inti)

{intj;

length>

=MAXNUM)

thelistisfull,cannotinsert."

return(false);

if(i<

1||i>

length+1)

\n%disinvalidvalue"

i);

for(j=lp->

length-1;

j>

=i-1;

j--)

data[j+1]=lp->

data[j];

data[i-1]=new_elem;

return(true);

intdeletelist(list_type*lp,inti)

intj;

length)

elemnotexist"

for(j=i;

j<

j++)

data[j-1]=lp->

length--;

voiddelete_negative(list_type*lp)

intt,i,p=0;

for(i=p;

i<

i++)

if(lp->

data[i]<

0&

&

length-1)

{

p=i;

for(t=i;

t<

t++)

lp->

data[t]=lp->

data[t+1];

i--;

lp->

}

elseif(lp->

i==lp->

voidmain()

{list_typelist;

inti,data;

createlist(&

list);

showlist(&

\ninsert:

Enterianddata:

%d,%d"

i,&

data);

insertlist(&

list,data,i);

\nlistafterinsert:

\ndelete:

Enteri:

%d"

i);

deletelist(&

list,i);

\nlistafterdelete:

delete_negative(&

\nlistafterdeleteallnegative:

/*ex1-2*/

#defineMAXNUM10

#defineelenum15

/*createalist*/

intinsertlist(list_type*lp,intnew_elem)

{intj,i;

for(j=0;

new_elem>

=lp->

data[j]&

j<

j++){}

for(i=lp->

i>

=j;

i--){

data[i+1]=lp->

data[i];

data[i+1]=new_elem;

intdata;

Enterdata:

list,data);

运行结果:

Ex1_1:

Ex1_2:

附录二

/*Ex2_1*/

#include<

malloc.h>

typedefstructnode_type//定义链点

structnode_type*next;

}node_type;

typedefstructlist_type//定义链表

node_type*head;

node_type*tail;

}list_type;

intread()

intx;

&

x);

returnx;

voiderror(intx)

switch(x)

case1:

printf("

\ntheplaceofthedataiswrong,pleaseinputtheplaceagain\n"

break;

voidcreat_list(list_type*node)//创建链表

node_type*p,*s;

//注意此处的指针要为链点结构体类型

node->

head=(node_type*)malloc(sizeof(node_type));

p=node->

head;

while(node->

5)//输入五个数

scanf("

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

s->

data=x;

p->

next=s;

p=s;

//在链点连接上出现了问题导致后面显示链表时也出问题

node->

p->

next=NULL;

tail=p;

}

voidshow_list(list_type*node)//把链表元素打印出来

node_type*p;

head->

next;

\nThelinkedlistis\n\n"

while(p!

=NULL)

printf("

%d"

p->

p=p->

//p往下走一步

}

\nThelengthofthislinkedlistis%d\n"

node->

voidinsert_list(list_type*node,intnewdata,intplace)

node_type*newnode,*p;

inti=0;

newnode=(node_type*)malloc(sizeof(node_type));

//动态申请内存

newnode->

data=newdata;

length+1<

place||place<

1)//判断插入的位置是否正确

error

(1);

place=read();

//位置错误则重新输入位置

while(i<

place-1)//使p指针指向插入位置的前一个

i++;

next=p->

//插入链点

next=newnode;

if(newnode->

next==NULL)

tail=newnode;

//若插入的位置为表尾,则改变尾指针

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

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1