忆月の日常

国家一级保护废物

0%

数据结构第1章

第一章 绪论

*第一台计算机诞生于1946年

创建结构体
1
2
3
4
5
6
struct Student
{
int No;
char name[20];
float Eng;
}stu[20];
结构体的使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<string.h>

int main()
{
struct Student stu1;

strcpy(stu1.name,"John");
stu1.No = 10000;
stu1.Eng = 87;

printBook(stu1);

return 0;
}

第二章

顺序表的构建
创建结构体
1
2
3
4
5
6
7
8
#include<stdio.h>
#include<stdlib.h>

typedef struct Vector{
int size; // 线性表容量
int length; // 当前元素个数
int *data; // 头指针
}Vector;
顺序表的初始化
1
2
3
4
5
6
void init(Vector *vector, int size)
{
Vector->size = size;
Vector->length = 0;
Vector->data = (int*)malloc(sizeof(int) * size);
}
清理内存函数
1
2
3
4
5
void clean(Vector *vector)
{
free(vector->data);
free(vector);
}
插入函数
1
2
3
4
void insert(Vector *vector, int loc, int value)
{

}