C语言中的一个链表!
来源:互联网 发布:腾讯代理吃鸡会优化么 编辑:程序博客网 时间:2024/05/18 16:54
struct element
{
char name[20];
char pwd[8];
struct element* next;
};
struct element* newElement(char * name ,char * pwd)
{
struct element* p = (struct element*)malloc(sizeof(struct element));
memset(p,'/0',sizeof(struct element));
strcpy(p->name,name);
strcpy(p->pwd,pwd);
p->next=0;
return p;
}
int add(struct element * head,struct element* ele)
{
if(head == 0)
{
head=ele;
return 1;
}
while(head->next!=0)
{
head=head->next;
}
head->next=ele;
return 1;
}
struct element* search(struct element * head ,char * name)
{
if(head == 0) return 0;
while(head->next != 0)
{
printf("%d/n",head);
if(strcmp(head->name,name)==0) return head;
head= head->next;
}
return 0;
}
int main()
{
struct element* e1= newElement("meng","123456");
struct element* e2= newElement("song","123123");
struct element* e3= newElement("li","123321");
printf("%d,%d/n",add(e1,e2),add(e1,e3));
struct element* e4= search(e1,"song");
printf("song pwd is :%s/n",e4->pwd);
}
以上代码在gcc编译器中编译通过,但运行出错!!,在cl编译器中运行出错!!
{
char name[20];
char pwd[8];
struct element* next;
};
struct element* newElement(char * name ,char * pwd)
{
struct element* p = (struct element*)malloc(sizeof(struct element));
memset(p,'/0',sizeof(struct element));
strcpy(p->name,name);
strcpy(p->pwd,pwd);
p->next=0;
return p;
}
int add(struct element * head,struct element* ele)
{
if(head == 0)
{
head=ele;
return 1;
}
while(head->next!=0)
{
head=head->next;
}
head->next=ele;
return 1;
}
struct element* search(struct element * head ,char * name)
{
if(head == 0) return 0;
while(head->next != 0)
{
printf("%d/n",head);
if(strcmp(head->name,name)==0) return head;
head= head->next;
}
return 0;
}
int main()
{
struct element* e1= newElement("meng","123456");
struct element* e2= newElement("song","123123");
struct element* e3= newElement("li","123321");
printf("%d,%d/n",add(e1,e2),add(e1,e3));
struct element* e4= search(e1,"song");
printf("song pwd is :%s/n",e4->pwd);
}
以上代码在gcc编译器中编译通过,但运行出错!!,在cl编译器中运行出错!!
- C语言中的一个链表!
- c语言中的一个问题
- C语言中的链表
- c 语言中的链表
- 一个C语言中的小知识点
- c语言中的一个小问题
- 删除一个字符串中的数字(C语言)
- c语言最后一个程序链表
- c语言链表出现一个错误
- c语言一个链表的实现
- c 语言:一个链表的实现
- C语言构建一个简单链表
- C语言中的双向循环链表
- C语言删除链表中的结点
- C 语言中的ADT 中的一个列表的问题
- 编写一个删除c语言中的注释语句/* */的程序
- C语言删除一个字符串中的多余空格字符
- C语言中的一个关于基本类型的输出问题
- IT项目经理管理技能的提升
- Ubuntu下安装Eclipse CDT
- vector list 和deque的优缺点
- 搜 索 引 擎 分 类
- CreateThread
- C语言中的一个链表!
- C++邻域查找
- The project cannot be built
- LR的一个输出状态信息的函数
- Banner大小之国际标准
- X3DAudio
- 3d游戏框架(第一个3d游戏实例)上
- 关于内存中栈和堆的区别[转]
- Fortran基本用法小结