#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
//#include <vld.h>
#include <string.h>
#define INIT_SIZE 100
#define SIZE 3
typedef struct Student
{
char id[15]; //15
char name[20]; //15+20
char sex[10]; //35+10
int age; //45+3 +4
double score[SIZE]; //52+4 +8*3
double sum; //80 +8
double avg; //88+8
}Student, *PStudent; //96
typedef struct Student_Head
{
struct Student* arr;//用来保存malloc返回的堆内内存块地址
int length;//当前空间已使用个数
int list_size;//当前空间总大小
}Student_Head, *PStudent_Head;
void Init_Student_Head(struct Student_Head *p)//初始化模块
{
assert(p != NULL);
if(p == NULL)
{
printf("指针为NULL\n");
return;
}
p->arr = (struct Student*)malloc(INIT_SIZE * sizeof(struct Student));
assert(p->arr != NULL);
p->length = 0;
p->list_size = INIT_SIZE;
}
static bool IsFull(PStudent_Head p)//判满操作
{
return p->length == p->list_size;
}
static void Inc(PStudent_Head p)//扩容操作
{
//*2
p->arr = (struct Student*)realloc(p->arr, p->list_size*sizeof(struct Student)*2);
assert(p->arr != NULL);
//p->length;//当前容量没有变化,只是将总空间变大两倍
p->list_size *= 2;
}
bool Add_Student(PStudent_Head p)//添加学生信息
{
assert(p != NULL);
if(p == NULL)
{
printf("指针为NULL\n");
return false;
}
if(IsFull(p))//判满
{
Inc
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交