0
点赞
收藏
分享

微信扫一扫

SpringBoot-读取配置文件内容

惠特曼 2024-08-15 阅读 29
数据结构

作业:创建单链表,存储4个学生信息(年龄,分数,姓名)。

1、建立学生结构体数组,存放4个学生信息,循环调用插入函数,建立整表

2、任意位置插入一个新学生。变量e是学生结构体变量。

3、任意位置删除一个学生。

4、单链表逆置后将学生信息输出。

main.c

#include"stu.h"
int main(int argc, const char *argv[])
{
	Pnode stu = input_stu();
	for(int i = 0;i<MAX;i++)
	{
		tail_insert(stu,input_stu());
	}
	return 0;
}

stu.c

#include"stu.h"

Pnode get_head()
{
	Pnode p = malloc(sizeof(Node));
	if(p==NULL)
	{
		printf("申请失败\n");
		return NULL;
	}
	p->len = 0;
	p->next = NULL;
	return p;
}

int input_stu(Pnode L)
{
	int i;
	for(i = 0;i<MAX;i++)
	{
		printf("请输入第%d个学生的姓名:\n",i+1);
		scanf("%s",L->data[i].name);
		printf("请输入第%d个学生的年龄:\n",i+1);
		scanf("%d",L->data[i].age);
		printf("请输入第%d个学生的成绩:\n",i+1);
		scanf("%d",L->data[i].score);
	}
	L->len++;
	return 0;

}

stu.h

#ifndef _STU_H_
#define _STU_H_
#include<myhead.h>
#define MAX 4

typedef struct stu
{
	char name[20];
	int age;
	int score;
};

typedef struct node
{
	union
	{
		stu data;
		int len;
	}
	struct node *next;
}Node,*Pnode;


#endif
举报

相关推荐

0 条评论