初始化元素为结构体的数组
严教材无法实现的地方
用指针实现数组快速复制
用指针交换结构体变量
进而实现冒泡排序
严教材无法实现的地方
#include <stdlib.h>
#include <malloc.h>
#define MAXSIZE 20
typedef struct
{
int time;
int value;
} corrd;
//为了排序不同个数组定义以下数据类型
typedef struct
{
corrd *a; //a[0]闲置
int length;
} SqList;
int InitList(SqList *L)
{
L->a=malloc(sizeof(corrd)*(MAXSIZE+1));
L->length=MAXSIZE+1;
return 1;
}
int main()
{
corrd c[4]={{0,0},{12,87},{7,43},{10,22}};
SqList L;
InitList(&L);
printf("%d\n",L.length);
L.a=c;
printf("%d %d",L.a[2].time,L.a[3].value);
return 0;
}
小作业小作业 文章被收录于专栏
小作业,姑且叫做操作步骤超过5步的作业吧