删除链表中指定元素
2016-03-06 08:44
239 查看
#include<stdio.h> #include<stdlib.h> #define N 5 #define NULL 0 #define OK 1 #define ERROR 0 typedef struct LNode { struct LNode *next; int data; }LNode,*list; void creatList(list &l,int n) { list p,q; int i; l=(list)malloc(sizeof(LNode)); p=l; for(i=0;i<n;i++) { q=(list)malloc(sizeof(LNode)); scanf("%d",&q->data); p->next=q; p=q; } p->next=NULL; } int insertDeleteList(list l,int e) { list p,q; p=l->next; q=l; while(p) { if(p->data==e) { while(q->next!=p)q=q->next; q->next=p->next; free(p); return OK; } p=p->next; } return ERROR; } void printList(list l) { list p; p=l->next; while(p) { printf("%d ",p->data); p=p->next; } } int main() { list l; int e; printf("input a list contain %d elements:\n",N); creatList(l,N); printf("input the number you need to delete:\n"); scanf("%d",&e); if(!insertDeleteList(l,e)) printf("NO\n"); else printList(l); return 0; }
相关文章推荐
- 进制转换
- 数据库索引的使用
- 日经春秋 20160306
- Win10 Mobile 10586.164中文版升级截图曝光
- 日经春秋 20160305
- 第19讲项目2——能对齐的数据
- c语言 变量交换函数
- 线程间通信与进程间通信
- Node.js模块封装及使用
- Codeforces 626D Jerry's Protest 「数学组合」「数学概率」
- SGU 242 Student's Morning 网络流(水
- 第19讲项目1——字母及其编码
- toms swgj steh ziyb
- Linux内核驱动自动创建设备节点文件
- A way to connect to network through WIFI on Centos 7
- JavaWeb开发 Tomcat安装及配置教程
- 不可视对象的自己主动实例化BUG
- JS面向对象编程详解
- 搭建可调试的微信公众平台本地测试环境
- Codeforces 626E Simple Skewness 「数学」「二分」