/*10.2-7-2011-05-08-19.40.c -- 第十章第二节第七题*/

#include

#include

/*明显常量定义*/

#define FALSE (0)

#define TRUE (1)

/*数据类型定义*/

typedef int BOOL ;

typedef int Item ;

typedef struct node

{

Item item ;

struct node * next ;

} Node ;

typedef Node * LinkedList ;

/*接口函数声明*/

void Initialize_L (LinkedList * const pl) ;

BOOL IsEmpty_L (const LinkedList * const pl) ;

BOOL Insert_L (LinkedList * const pl, const Item item) ;

void Traversal_L (const LinkedList * const pl, void (* pfun) (const Item item)) ;

void Release_L (LinkedList * const pl) ;

/*接口函数定义*/

void Initialize_L (LinkedList * const pl)

{

*pl = NULL ;

}

BOOL IsEmpty_L (const LinkedList * const pl)

{

if (NULL == *pl)

return TRUE ;

else

return FALSE ;

}

BOOL Insert_L (LinkedList * const pl, const Item item)

{

Node * newNode ;

newNode = (Node *) malloc (sizeof (Node)) ;

if (NULL == newNode)

return FALSE ;

newNode -> item = item ;

if (IsEmpty_L (pl))

{

newNode -> next = NULL ;

*pl = newNode ;

}

else

{

newNode -> next = *pl ;

*pl = newNode ;

}

return TRUE ;

}

void Traversal_L (const LinkedList * const pl, void (* pfun) (const Item item))

{

Node * scan ;

for (scan = *pl; scan != NULL; scan = scan -> next)

(* pfun) (scan -> item) ;

}

void Release_L (LinkedList * const pl)

{

Node * scan, * temp ;

scan = *pl ;

while (scan != NULL)

{

temp = scan ;

scan = scan -> next ;

free (temp) ;

}

*pl = NULL ;

}

/*主例程*/

int mian (void) ;

void printItem (const Item item) ;

void reverse (LinkedList * const pl) ;

int main (void)

{

LinkedList list ;

Item item ;

Initialize_L (&list) ;

item = 1 ;

Insert_L (&list, item) ;

item = 2 ;

Insert_L (&list, item) ;

item = 3 ;

Insert_L (&list, item) ;

item = 4 ;

Insert_L (&list, item) ;

item = 5 ;

Insert_L (&list, item) ;

Traversal_L (&list, printItem) ;

reverse (&list) ;

Traversal_L (&list, printItem) ;

Release_L (&list) ;

return 0 ;

}

void printItem (const Item item)

{

printf ("%-3d/n", item) ;

}

void reverse (LinkedList * const pl)

{

Node * current, * next, * temp ;

/*If linkedlist is empty or only has one node.*/

if (IsEmpty_L (pl) || NULL == (*pl) -> next)

return ;

current = *pl ;

next = current -> next ;

while (next -> next != NULL)

{

temp = next -> next ;

next -> next = current ;

current = next ;

next = temp ;

}

next -> next = current ;

(*pl) -> next = NULL ;

*pl = next ;

}

逆置单链表c语言程序,逆置单链表C语言相关推荐

  1. c语言程序第一章编程,c语言程序的设计第一章 C语言编程入门.ppt

    c语言程序的设计第一章 C语言编程入门 第1章 C语言编程入门 本章是本书的入门篇,专为初学者熟悉编程过程.掌握程序结构而准备的. 本章学习目标 ? 1)? 能够通过模仿与改变来构造带有测试函数的C语 ...

  2. 统计字符 c语言程序,统计字符个数的C语言程序.doc

    统计字符个数的C语言程序.doc 下载提示(请认真阅读)1.请仔细阅读文档,确保文档完整性,对于不预览.不比对内容而直接下载带来的问题本站不予受理. 2.下载的文档,不会出现我们的网址水印. 3.该文 ...

  3. c语言程序与设计苏小红,c语言程序设计苏小红

    <实验教学示范中心建设教材·国家精品课程主讲教材:C语言程序设计(第2版)>是一本兼具趣味性和实用性的C语言程序设计教材.全书由13章组成,内容包括:为什么要学C语言,C数据类型,简单的算 ...

  4. 电子时钟单片机c语言程序,51单片机电子时钟C语言程序

    本程序基于ATM89系列单片机的电子时钟C语言程序,能显示月日时分秒,同时还能调节其值!显示方式用六个8段数码管! #include//头文件 #define uchar unsigned char/ ...

  5. c语言程序中的基本功能,c语言程序中的基本功能模块为什么?

    c语言程序中的基本功能模块为"函数".一个C语言程序可以由一个主函数和若干个函数构成:一个大的应用程序一般应该分为多个程序模块,每一个模块用来实现一个功能,而模块的功能是由函数完成 ...

  6. 重庆理工大学c语言程序实验报告,重庆理工大学-C语言程序实验报告.doc

    重庆理工大学-C语言程序实验报告 程序设计基础C实验报告 PAGE 47 <程序设计基础C> 实 验 报 告 教学班级: 学号: 姓名: 课程教师: 实验辅导教师: 重庆理工大学计算机学院 ...

  7. c语言程序中cost的作用,C语言考试题基础版(21页)-原创力文档

    if (x>y)z=x; s=z*z;elsez=y;s=1/(z*z); if (x>y) z=x; s=z*z; else z=y;s=1/(z*z); 7. B. C. PAd, P ...

  8. c语言程序的入口是哪部分,C语言入口函数和LD_PRELOAD环境变量

    零.C语言入口函数 从第一天学习C语言开始,我们的脑子里就深深烙下这样一个概念:C语言程序总是从main()函数开始执行,main()函数结束,程序也就结束了.在平时的练习中貌似这没有问题,但事实真的 ...

  9. 避障跟随测距c语言程序,红外避障小车c语言程序.pdf

    智能小车红外避障智能小车红外避障 c 语言程序语言程序 #include bit RandomFactor = 0 ; bit RandomFactorBuf = 0 ; #include #defi ...

  10. c语言程序一些常见的不足,C语言常见错误分析及解决方法

    C.C语言的应用很广泛,越来越多的程序员希望能够学好C由于C语言的编译系统对语法的检查不如其他语言那么严格,因此C语.下面将C语言中初学者最常见的错误分析如下; 1 语句书写错误 由于大部分学生都是初 ...

最新文章

  1. 获取元素到页面顶部的距离_组成网站页面结构的元素有哪些?
  2. YARN应用场景、原理与资源调度
  3. php扩展 waf,基于PHP扩展的WAF实现
  4. 深度linux deepin 12.12,Linux Deepin 12.12 Beta 发布
  5. python 编译器pyc_有没有办法知道哪个Python版本.pyc文件被编译?
  6. linux下的汇编,linux下的汇编分析
  7. 2012年8月20日 我单身了!
  8. 十几个NPM恶意包劫持 Discord 服务器
  9. 留言板删除功能mysql_用PHP写留言板代码时怎样才能实现删除和修改留言的啊?代码是怎样的?...
  10. 详解VMware虚拟机中添加新硬盘并挂载的方法
  11. mysql实时监控工具
  12. Data Shapley: Equitable Valuation of Data for Machine Learning(翻译)
  13. docker 启动 redis cluster,使用出现CLUSTERDOWN Hash slot not served(redis cluster重新分配slot)
  14. 奔驰首秀L4自动驾驶:100万最贵电动车展示最豪华「AI代客泊车」
  15. 在Android上应用PhoneGap和Dojo Mobile
  16. Matplotlib数据可视化画图
  17. 陀螺仪的简单介绍讲解
  18. Android系统介绍与框架
  19. IOS单例模式及单例模式的优缺点
  20. hardware计算机专业英语翻译,hardware是什么意思中文翻译

热门文章

  1. 循环神经网络(LSTM和GRU)(1)
  2. 爬楼梯 · Climbing Stairs
  3. Spring Framework--Data Access(1)--Transaction Management(2) - 声明式事务管理
  4. CCF NOI1011 正方形
  5. B00003 C++标准库 std::bitset
  6. Python 标准库 —— json
  7. Python 库的使用 —— dis
  8. 重复抽样与非重复抽样
  9. 物理学基石 —— 波、电磁波、微波
  10. 椭圆基本概念、定理及性质