- 1、本文档共4页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
二叉树程序可运行
#include stdio.h
#include malloc.h
#include stdlib.h
typedef int ELEMTYPE;
struct node {
ELEMTYPE element;
struct node *next;
};
struct node *head;
struct node *tail;
void init()
{
head=(struct node *)malloc(sizeof(struct node));
if (!head) exit(0);
head-next=NULL;
tail=head;
}
int isEmpty()
{
if (head==tail) return 1;
else return 0;
}
int length()
{
struct node *p;
int cnt=0;
for (p=head-next;p!=NULL;p=p-next)
cnt++;
return cnt;
}
void append(ELEMTYPE item)
{struct node *p;
p=(struct node *)malloc(sizeof(struct node));
if (!p) exit(0);
p-element=item;
p-next=tail-next;
tail-next=p;
tail=p;
}
struct node *search(ELEMTYPE item)
{
struct node *p;
p=head-next;
while(p!=NULL)
{
if (p-element==item)
return p;
else
p=p-next;
}
return NULL;
}
void traversal()
{
struct node *p;
printf (list is :);p=head-next;
for(p=head-next;p!=NULL;p=p-next)
printf (%d ,p-element);
printf (\n);
}
void invert()
{struct node *p,*q,*k;
p=head-next ;q=p-next ;k=q-next ;
while(k)
{q-next =p;
p=q;
q=k;
k=q-next;
}
q-next=p;
head-next-next=NULL;
head-next =q;
}
/*void del_k(ELEMTYPE k)
{struct node *p,*q;p=head-next;
while(p!=NULL)
{if(p-element==k)
{q=head-next;
while(q-next!=p)
q=q-next;
q-next=p-next;
q=p;
p=p-next;
free(q);}
else p=p-next;}
}*/
void del_k(ELEMTYPE k)
{struct node *p,*q;p=head-next;
while(p!=NULL)
{if(p-element==k)
{q=head-next;
while(q-next!=p)
q=q-next;
q-next=p-next;
q=p;
p=p-next;
free(q);}
else p=p-next;}
}
int main()
{
init();
append(1);
append(2);
append(3);
append(4);
append(5);
append(2);
del_k(2);
traversal();
invert();
traversal();
del_k(3);
traversal();
}
您可能关注的文档
- 综合与实践:生活与百分数1.ppt
- 驻马店高级中学校本研修计划.doc
- 高考3500词汇练.ppt
- (高二)记住这150条短语,月考英语至少涨20分!.docx
- 能力提升工程学习简报第01期.pptx
- 新概念英语第一册141--142课课件.ppt
- 跳芭蕾舞的牛3.pptx
- M7i路由器配置手册.doc
- 研析整理之路.pptx
- 中概股回归以奇虎360为例.pptx
- 2025至2030年中国特种泵数据监测研究报告.docx
- 2025至2030年中国猫眼石手镯数据监测研究报告.docx
- 2025至2030年中国独立型高速裁线机数据监测研究报告.docx
- 2025至2030年中国獭兔包数据监测研究报告.docx
- 2025至2030年中国玉柴机器用油数据监测研究报告.docx
- 2025至2030年中国玩具专用型检针器数据监测研究报告.docx
- 2025至2030年中国环丁砜数据监测研究报告.docx
- 2025至2030年中国环氧树脂干式变压器绝缘浇注料数据监测研究报告.docx
- 2025至2030年中国环保添加剂数据监测研究报告.docx
- 2025至2030年中国环保空调外壳数据监测研究报告.docx
文档评论(0)