资源简介
一个学生管理系统,用C开发的,基于所学习的数据结构的链表知识开发。
代码片段和文件信息
#include
#include
#include
using namespace std;
struct student
{
char name[20];
//char *name1;
int num;
char sex;
float score;
struct student *next;
};
int n;
void main()
{
struct student *head = NULL;
struct student *pb1*pbb;
struct student * creat(struct student*headint n);
struct student * insert(struct student*headint n1struct student *q);
bool find(struct student *headint numb);
struct student *del(struct student *headint n1);
cout<<“请输入你想创建的链表的节点个数:“< cin>>n;
head = creat(headn);
pb1 = head;
if(head==NULL)
cout<<“Error!“<
for(int i=1;i<=n;i++)
{ cout<name<<“ “<num<<“ “<sex<<“ “<score< pb1 = pb1->next;
}
cout< pbb = (struct student*)malloc(sizeof(struct student));
gets(pbb->name);
pbb->num = 004;
pbb->sex = ‘F‘;
pbb->score = 100;
pb1= insert(head2pbb);
do{
cout<name<<“ “<num<<“ “<sex<<“ “<score< pb1 = pb1->next;
}while(pb1->next!=NULL);
cout<name<<“ “<num<<“ “<sex<<“ “<score< cout< pb1 = del(head2);
do{
cout<name<<“ “<num<<“ “<sex<<“ “<score< pb1 = pb1->next;
}while(pb1->next!=NULL);
cout<name<<“ “<num<<“ “<sex<<“ “<score< cout<<“现在查找“< if(find(head123))
cout<<“找到!“< else
cout<<“没找到!“<
}
struct student *creat(struct student * headint n)
{
struct student *pf*pb;
for(int i=1;i<=n;i++)
{
pb = (struct student *)malloc(sizeof(struct student));
cout<<“输入姓名:“< cin>>pb->name;
cout<<“输入学号:“< cin>>pb->num;
cout<<“输入性别和分数“< cin>>pb->sex>>pb->score;
if(i==1)
{
head = pb;
pf = pb;
pf ->next = NULL;
}
else
{
pf->next = pb;
pf = pb;
pf->next = NULL;
}
}
return (head);
}
struct student * insert(struct student*headint n1struct student *q)
{
struct student *pf;
pf = head;
if(n1==1)
{
q->next = head;
head = q;
}
else if(n1>1 && n1<=n)
{
for(int i=1;i {
pf = pf->next;
}
q->next = pf->next;
pf->next = q;
}
if(n1==n+1)
{
q->next=NULL;
for(int j=1;j {
pf = pf->next;
}
q = pf->next;
}
return head;
}
struct student *del(struct student *headint n1)
{
struct student *pb*pf;
pf =head;
if(n1 == 1)
{
head = head->next;
}
else if(n1>1&&n1 {
for(int j=1;j {
pf = pf->next;
}
pb = pf->next;
pf->next = pb->next;
}
if(n1== n)
{
pf ->next=NULL;
}
return head;
}
bool find(struct student *headint numb)
{
struct student *pb;
pb = head;
for(int i=1;i<=n;i++)
{
if(pb->num==numb)
{
return true;
}
pb=pb->next;
}
return false;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 553023 2010-06-28 16:46 lianbiao\Debug\lianbiao.exe
文件 789708 2010-06-28 16:46 lianbiao\Debug\lianbiao.ilk
文件 268747 2010-06-28 16:46 lianbiao\Debug\lianbiao.obj
文件 2064500 2010-06-28 11:54 lianbiao\Debug\lianbiao.pch
文件 1098752 2010-06-28 16:45 lianbiao\Debug\lianbiao.pdb
文件 82944 2010-06-28 16:46 lianbiao\Debug\vc60.idb
文件 118784 2010-06-28 16:45 lianbiao\Debug\vc60.pdb
文件 3002 2010-06-28 16:47 lianbiao\lianbiao.cpp
文件 4302 2010-06-28 11:59 lianbiao\lianbiao.dsp
文件 897 2010-06-28 16:46 lianbiao\lianbiao.plg
文件 0 2010-06-28 10:57 lianbiao\shishi.cpp
目录 0 2010-06-28 20:27 lianbiao\Debug
目录 0 2010-06-28 20:27 lianbiao
----------- --------- ---------- ----- ----
4984659 13
- 上一篇:pfx证书工具
- 下一篇:retro_snake.c
评论
共有 条评论