网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > C/C++
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.用CB在WIN.INI中保存信息.
.深入研究 C++中的 STL Deque 容器.
.C++类和接口的设计原则探讨.
.第 1 章 贪婪算法.
.《C语言程序设计》教学的几点体会.
.Windows中控制台程序的全屏模式开.
.创建C++ Builder菜单.
.在Tc2.0下的鼠标控制程序.
.C语言库函数(S类字母)-2.
.认识宏,C语言的万恶之首.
.显示消息框的程序.
.C/C++指针应用.
.C语言入门之循环结构.
.指针的地址分配.
.C++箴言:多态基类中将析构函数声.
.C++中实现Java的存储管理机制.
.C++/CLI实战——HELLO.
.一个简易的proxy程序的开发过程(.
.什么是迭代跟递归算法?二者有什.
.用C实现exp函数!.

c语言最经典的链表

发表日期:2008-3-8



  在turbo c 2.0 下调试通过.(把汉语注释去掉) #include"stdio.h" #include"malloc.h" #define NULL 0 #define L sizeof(strUCt integer) struct integer /*定义结构体*/ { int num; int zhengshu; struct integer *next; }; int n; //纪录链表的长度 struct integer *creat(void) /*创建链表*/ { struct integer *head; struct integer *p1,*p2; n=0; p1=p2=(struct integer *)malloc(L); scanf("%d,%d",&p1->num,&p1->zhengshu); head=NULL; while(p1->num!=0) { n=n+1; if(n==1) head=p1; else p2->next=p1; p2=p1; p1=(struct integer *)malloc(L); scanf("%d,%d",&p1->num,&p1->zhengshu); } p2->next=NULL; return(head); } void print(struct integer *head) /*打印链表中的数据*/ { struct integer *p; printf("Now %d biaohao and zhengshu are :n",n); p=head; if(head!=NULL) do {printf("%d,%5.1dn",p->num,p->zhengshu); p=p->next; }while(p!=NULL); } int count(struct integer *head) /*返回链表的长度*/ { int i=0; struct integer *p; p=head; while(p!=NULL) { p=p->next;i++; } return i; } void *findnode(struct integer *head,int num) /*查找链表中的第num个数据*/ { int j=1; struct integer *p; /*if(head==NULL) { printf("n空链表,请先创建!n"); return; }*/ p=head; if(num>count(head)num<=0) { printf("Input error! Please input againn"); } else { while(p!=NULL && jnext; } printf("%d bianhao reprensts %dn",p->num,p->zhengshu); printf("n"); } return(head); } struct integer *del(struct integer *head,long num) /*删除链表中的第num个数据*/ { struct integer *p1,*p2; if(head==NULL) { printf("nList Null!n"); return; } p1=head; while(num!=p1->num && p1->next!=NULL) { p2=p1; p1=p1->next; } if(num==p1->num) { if(p1==head) head=p1->next; else p2->next=p1->next; printf("Delete: %dn",num); n=n-1; } else printf("%d not been fonnd!n",num); return(head); } struct integer *insert(struct integer *head,struct integer *stud) /*插入数据*/ { struct integer *p0,*p1,*p2; p1=head; p0=stud; if(head==NULL) { head=p0; p0->next=NULL; } else { while((p0->num>p1->num)&&(p1->next!=NULL)) { p2=p1; p1=p1->next; } if(p0->num<=p1->num) { if(head==p1)head=p0; else p2->next=p0; p0->next=p1; } else { p1->next=p0; p0->next=NULL; } } n=n+1; return(head); } main() /*主功能函数*/ { int a,b; struct integer *head,stu;
int del_num,fin_num; printf("1 to go on / 0 to exit:n"); scanf("%d",&a); while(a!=0) { /*struct integer *head,stu; int del_num;*/ printf("1 creat 2 print 3 delete 4 insert 5 findonde 0 exitn"); /*菜单的实现*/ scanf("%d",&b); switch(b) { case 1: { /*clrscr();*/ printf("Please Input bianhao and data:n"); printf("for example 1,90 0,0 to exit:n"); head=creat(); }break; case 2: { /*clrscr();*/ print(head); }break; case 3: { /*clrscr();*/ printf("nInput the deleted biaohao:"); scanf("%d",&del_num); head=del(head,del_num); }break; case 4: { /*clrscr();*/ printf("nInput the inserted biaohao and zhengshu:"); scanf("%d,%d",&stu.num,&stu.zhengshu); head=insert(head,&stu); }break; case 5: { /*clrscr();*/ printf("Please Input the bianhao you want to find:"); scanf("%d",&fin_num); head=findnode(head,fin_num); }break; case 0: { return; }break; default: printf("Input error! Please input againn"); } } }

上一篇:Device Drivers(设备驱动程序) 人气:556
下一篇:DriverStudio工具包介绍 人气:1419
浏览全部C/C++的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐