学生-简单链表
来源:互联网 发布:傻瓜式园林设计软件 编辑:程序博客网 时间:2024/06/11 16:26
#include <stdio.h>#include <stdlib.h>#include <malloc.h>struct node{ int num; char str[20]; struct node *next;};int main(){ struct node *creat(); struct node *insert(); struct node *Delete(); void print(); struct node *head; char str[20]; int n; head=NULL; head=creat(head); print(head); printf("\ninput insert num ,name:\n"); gets(str); n=atoi(str); gets(str); head=insert(head,str,n); print(head); printf("\ninput delete name :\n"); gets(str); head=Delete(head,str); print(head); return 0;}struct node* creat(struct node *head){ char temp[30]; struct node *p1,*p2; p1=p2=(struct node *)malloc(sizeof(struct node)); printf("input num,name:\n"); printf("exit:double times Enter !\n"); gets(temp); gets(p1->str); p1->num=atoi(temp); p1->next=NULL; while(strlen(p1->str)>0) { if(head==NULL) head=p1; else p2->next=p1; p2=p1; p1=(struct node*)malloc(sizeof(struct node)); printf("input num,name:\n"); printf("exit:double times Enter!\n"); gets(temp); gets(p1->str); p1->num=atoi(temp); p1->next=NULL; } return head; }struct node *insert(head ,pstr,n)struct node * head;char *pstr;int n;{ struct node *p1,*p2,*p3; p1=(struct node*)malloc(sizeof(struct node)); strcpy(p1->str,pstr); p1->num=n; p2=head; if(head==NULL) { head=p1; p1->next=NULL; } else { while(n>p2->num&&p2->next!=NULL) { p3=p2; p2=p2->next; } if(n<=p2->num) if(head==p2) { p1->next=p2; head=p1; } else { p1->next=p2; p3->next=p1; } else {p2->next=p1; p1->next=NULL;} } return (head);}struct node* Delete(head,pstr)struct node *head;char *pstr;{ struct node *temp,*p; temp=head; if(head==NULL) printf("\n List is NULL!"); else { temp=head; while(strcmp(temp->str,pstr)!=0&&temp->next!=NULL) { p=temp; temp=temp->next; } if(strcmp(temp->str,pstr)==0) { if(temp==head) { head=head->next; free(temp); } else { p->next=temp->next; printf("delete string:%s\n",temp->str); free(temp); } } else printf("\n mo find sting!\n"); } return head; } void print(struct node* head ) { struct node* temp; temp=head; printf("\noutput string :\n"); while(temp!=NULL) { printf("\n%d---%s\n",temp->num,temp->str); temp=temp->next; } return; }
0 0
- 学生-简单链表
- 简单学生系统----使用链表编写
- 简单的学生信息链表
- 链表实现简单学生信息管理
- 简单的学生信息表
- 顺序表实现简单学生信息管理
- 学生链表1
- 学生信息链表
- 一个简单的学生信息管理系统(循环双向链表)
- 简单的学生成绩管理系统
- 简单的学生成绩管理系统
- 简单学生成绩管理系统
- 超简单学生成绩管理系统
- 简单的学生成绩管理系统
- 简单学生管理系统
- 简单学生管理系统
- 学生成绩简单统计
- 简单学生信息管理系统
- 测试计划管理
- 循环链表
- 日报2015/10/16(极客学院安卓视频学习)
- bfs例题:血色先锋军
- 多线程解析
- 学生-简单链表
- Julia : 又一次 ”协变“ 中招!
- 微信第三方平台的开发过程一
- 进程间通信-共享内存
- js ajax
- Spring MVC 中 HandlerInterceptorAdapter过滤器的使用
- 先序遍历的非递归算法
- 大端模式和小端模式
- 浅谈Java虚拟机的工作模式Client和Server。