单链表的创建
2016-01-28 16:48
323 查看
typedef struct node // { char num; struct node *next; }; /******************************************/ struct node*creat(struct node *head)/*返回的是与节点相同类型的指针*/ { struct node *pNew,*pEnd; //p2为尾指针 char ch; head = null;//链表开始为空。 pEnd = null; //尾指针初始为空。 ch=getchar(); while(ch != '\n') { pNew =(struct node*)malloc(sizeof(struct node));//新节点 pNew->data = ch; if(head == NULL) { head=pNew; //空表,接入表头 } else { pEnd->next=pNew; //非空表,将新节点接到表尾 pEnd = pNew; // } ch=getchar(); // 读入下一字符 } if(pEnd != null) { pEnd->next = null; } return head; } /*******************************************/ void print(struct node*head)/*出以head为头的链表各节点的值*/ { struct node *temp; temp=head;/*取得链表的头指针*/ while(temp!=NULL)/*只要是非空表*/ { printf("%6d",temp->num);/*输出链表节点的值*/ temp=temp->next;/*跟踪链表增长*/ } } main( ) { struct node *creat(); void print(); struct node *head; head=NULL; head=creat(head); print(head); }
相关文章推荐
- Linux下安装Nginx详细图解教程
- 简单例子解释invalidate(), requestLayout() (常用还是需要知道的)
- HDU 3501 Calculation 2 (欧拉函数)
- Android自定义View(二)
- adb shell下使用命令行删除android系统中指定文件和文件夹
- 可编程DMA控制器——Intel 8257介绍
- Android开发笔记-Eclipse和Android Studio的偏好设置Preferences的导出与导入
- Ecplise 背景颜色修改
- Java容器总结 干货
- hbase1.0.0搭建步骤
- 解决HttpClient在Android5.0系统上无效的问题
- 简单例子解释invalidate(), requestLayout() (常用还是需要知道的)
- MyBatis-generator-core 生成的Dao 怎么自定义名字 (或者手动修改哪些源码可以实现)
- 【QTP】自动化测试:
- 框架组合
- 图示邮件服务器工作原理
- 图示邮件服务器工作原理
- 电脑无法获取IP地址
- LeeCode Invert Binary Tree
- 比较MongoDB在公有云上的性能:AWS、Azure和Digital Ocean