单链表(C实现)
来源:互联网 发布:燕雀焉知鸿鹄之志图片 编辑:程序博客网 时间:2024/04/30 08:51
#ifndef _LIST_H //list.h#define _LIST_Htypedef struct _node{<span style="white-space:pre"></span>void *data;<span style="white-space:pre"></span>struct _node *next;}NODE;typedef struct{<span style="white-space:pre"></span>NODE *head;<span style="white-space:pre"></span>NODE *last;<span style="white-space:pre"></span>int length;}LIST;LIST *InitList();int InsertList(LIST *l,void *data,int size);NODE * FindNodeByKey(LIST *l,void *key,int (*compare)(void *,void *));int DeleteListByKey(LIST *l,void *key,int (*compare)(void *,void *));#endif
//顺序表和链表是如何实现通用性的//typedef void *#include "list.h"//main.c#include <stdio.h>#include <stdlib.h>#include <string.h>struct STU{char sno[5];char name[21];int age;float score;}s[3]={{"S001","lin wu",12,90},{"S002","xiao ming",18,80},{"S003","hu wu",19,70}};//也可以通过比较其他的键值来查找,比如年龄,分数。int CompareByName(void *info,void *key){struct STU *stu=(struct STU *)info;char *name=(char *)key;return strcmp(stu->name,name)==0?1:0;}int CompareBySno(void *info,void *key){struct STU *stu=(struct STU *)info;char *sno=(char*)key;return strcmp(stu->sno,sno)==0?1:0;}void main(){int i; NODE *p=NULL;char name[]="xiao ming",sno[]="S001";NODE *res=NULL; LIST *list=InitList();for(i=0;i<3;i++){InsertList(list,&s[i],sizeof(s[i]));} res=FindNodeByKey(list,name,CompareByName);if(res==NULL)printf("Not Find\n");elseprintf("Find\n");if(DeleteListByKey(list,sno,CompareBySno)) printf("delete success\n");elseprintf("delete fail\n");}
VC6运行效果图
VC6调试过程
插入3个元素
删除其中一个
0 0
- 单链表(C#)实现
- 单链表实现(C++)
- 单链表(C实现)
- 单链表基本实现(c++)
- 数据结构(C实现)------- 单链表
- 单链表逆序(c实现)
- 单链表合并(c实现)
- 【数据结构】实现单链表(c++)
- C实现C(二)
- C#入门(8)-实现单链表
- 数据结构之单链表实现栈(C++)
- 数据结构之单链表实现(C++)
- 递归逆序打印单链表(c实现)
- 数据结构之单链表(C语言实现)
- c::单链表的实现(值得一看)
- 单链表的实现操作(C语言)
- 用C实现单链表
- C实现单链表
- JSON和XML的区别
- Kibana User Guide [4.2] » Visualize » Data Table
- Android 触摸手势基础 官方文档概览
- 实习三个月小结
- Android 注册小实例
- 单链表(C实现)
- 1009. 说反话 (20)
- 实现C/S程序的自动更新2
- weblogic 服务开机自动启动
- 谈谈使用VFW在windows下编程控制摄像头(一)。 【孙涛】
- 【五】注入框架RoboGuice使用:(Your First POJO Injection)
- 数据压缩与信息熵
- 给我们自己一个空间—兄弟连IT教育
- IM类应用架构所需了解