成绩查询线性表c语言,请帮忙编写一个程序 ,关于查找、删除 、插入的同学成绩 的线性表 ,C语言的数据结构...

该博客介绍了使用C语言实现学生信息管理的三个基本操作:查找成绩、删除成绩和插入成绩。通过结构体数组存储学生姓名和电话号码,实现了对数据的读取、查找和删除功能。同时,展示了如何动态插入节点到链表中,以管理学生分数。
摘要由CSDN通过智能技术生成

匿名用户

1级

2014-03-28 回答

1、查找成绩

#include

#include

#define MAX 101

struct aa/*定义结构体aa存储姓名和电话号码*/

{

char name[15];

char tel[15];

};

int readin(struct aa *a)/*自定义函数readin,用来存储姓名及电话号码*/

{

int i=0,n=0;

while(1)

{

scanf("%s",a[i].name);/*输入姓名*/

if(!strcmp(a[i].name,"#"))

break;

scanf("%s",a[i].tel);/*输入电话号码*/

i++;

n++;/*记录的条数*/

}

return n;/*返回条数*/

}

search(struct aa *b,char *x,int n)/*自定义函数search,查找姓名所对应的电话号码*/

{

int i;

i=0;

while(1)

{

if(!strcmp(b[i].name,x))/*查找与输入姓名相匹配的记录*/

{

printf("name:%s tel:%s\n",b[i].name,b[i].tel);/*输出查找到的姓名所对应的电话号码*/

break;

}

else

i++;

n--;

if(n==0)

{

printf("No found!");/*若没查找到记录输出提示信息*/

break;

}

}

}

main()

{

struct aa s[MAX];/*定义结构体数组s*/

int num;

char name[15];

num=readin(s);/*调用函数readin*/

printf("input the name:");

scanf("%s",name);/*输入要查找的姓名*/

search(s,name,num);/*调用函数search*/

}

2、删除成绩

#include "stdio.h"

struct student

{

int num;

struct student *next;

};

struct student *create(int n)

{

int i;

struct student *head, *p1, *p2;

int a;

head = NULL;

printf("The record:\n");

for (i = n; i > 0; --i)

{

p1 = (struct student*)malloc(sizeof(struct student)); /*分配空间*/

scanf("%d", &a);

p1->num = a; /*数据域赋值*/

if (head == NULL)

{

head = p1;

p2 = p1;

}

else

{

p2->next = p1; /*指定后继指针*/

p2 = p1;

}

}

p2->next = NULL;

return head;

}

struct student *delnode(struct student *head, int i)

{

int j = 0;

struct student *p, *r;

p = head;

while (p && j < i - 1)

{

p = p->next;

++j;

}

if (!p->next || j > i - 1)

exit(1);

r = p->next;

p->next = r->next;

free(r);

}

void main()

{

int n, i;

int x;

struct student *q;

printf("Input the count of the nodes you want to creat:");

scanf("%d", &n);

q = create(n);

i = 2;

delnode(q, i);

printf("The third record is deleted!\nThe result is:\n");

while (q)

{

printf("%d ", q->num);

q = q->next;

} getch();

}

3、插入成绩

#include "stdio.h"

struct student

{

int num;

struct student *next;

};

struct student *create(int n)

{

int i;

struct student *head, *p1, *p2;

int a;

char b;

head = NULL;

printf("The record:\n");

for (i = n; i > 0; --i)

{

p1 = (struct student*)malloc(sizeof(struct student)); /*分配空间*/

scanf("%d", &a);

p1->num = a; /*数据域赋值*/

if (head == NULL)

{

head = p1;

p2 = p1;

}

else

{

p2->next = p1; /*指定后继指针*/

p2 = p1;

}

}

p2->next = NULL;

return head;

}

struct student *insertnode(struct student *head, char x, int i)

{

int j = 0;

struct student *p, *s;

p = head;

while (p && j < i - 1)

{

p = p->next;

++j;

}

if (!p || j > i - 1)

exit(1);

s = (struct student*)malloc(sizeof(struct student));

s->num = x;

s->next = p->next;

p->next = s;

}

void main()

{

int n, i;

int x;

struct student *q;

printf("Input the count of the nodes you want to creat:");

scanf("%d", &n);

q = create(n);

i = 2;

x = 123;

insertnode(q, x, i);

printf("The result is:\n");

while (q)

{

printf("%d ", q->num);

q = q->next;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值