书上的代码总觉得有点问题
来源:互联网 发布:百度糯米用不了网络 编辑:程序博客网 时间:2024/06/01 23:22
#include <stdio.h>#include <stdlib.h>struct link *AppendNopde(struct link *head);void DisplyNode(struct link *head);void DeleteMemory(struct link *head);struct link{ int data ; struct link *next;};int main(){ int i=0; char x; struct link *head = NULL; printf("Do you want to append a new node ?\n"); scanf("%c",&x); while(x=='y') { head = AppendNopde(head); DisplyNode(head); printf("Do you want to append a new node ?\n"); scanf("%c",&x); ++i; } printf("%d new nodes had been appended \n",i); DeleteMemory(head); return 0;}struct link *AppendNopde(struct link *head){ struct link *p = NULL,*pr = head; int data; p = (struct link *)malloc(sizeof(struct link)); if (p==NULL) { printf("No enough memory to \n"); exit(0); /* code */ } if (head==NULL) { head = p; /* code */ } else { while(pr->next!=NULL) pr=pr->next; pr->next=p; } printf("Input node data:\n"); scanf("%d",&data); p->data = data; p->next = NULL; return head;}void DisplyNode(struct link*head){ struct link *p = head; int j =1; while (p!=NULL) { printf("%5d%10d\n",j,p->data); p = p->next; ++j; }}void DeleteMemory(struct link *head){ struct link *p = head ,*pr = NULL; while (p!=NULL) { pr = p; p = p->next; free(pr); }}
1 0
- 书上的代码总觉得有点问题
- 总觉得这篇文章有点搞
- 我觉得有点用的js代码
- 有点问题的代码
- 总觉得晚上的时间
- 《Programming In Lua》书上一个有问题的代码
- uva 213 - Message Decoding (我觉得我的方法要比书上少很多代码,不保证好……)
- 原来新建一个类,需要那么长的代码,瞬间觉得有点疲惫了 ~
- 觉得有点自豪的一些项目
- css居中的一些问题,我觉得有点用处,先收藏起来啦!
- html5一些比较实用的知识问题,个人觉得有点意思!
- 觉得好的代码
- 总该有点自己的东西!
- 总有点记不住的小东西
- 突然觉得有点累
- Linux作业(一)-Linux下文件及目录的权限问题(没试之前我也觉得有点奇怪)
- 丁老师的作业,书上的代码
- 书上的代码-起泡排列法
- OC中图片格式转化为二进制数组
- HDOJ 2546 饭卡 【0 1 背包】
- ChromeBook 使用 Android 手机 实现 首次 登录 激活
- sicily 1021. Couples
- CRF++
- 书上的代码总觉得有点问题
- C++设计模式[十二]职责链模式
- 观察者模式
- 大数据下的日志-flume(一)简介及例子
- 动态规划法解决0-1背包问题(C++)
- 【Android】TextView 显示超链接的几种方法
- Mac 环境变量配置
- Git学习整理
- 笔记二(触摸位置)