mirror of
https://github.com/ViolentAyang/DataStructureC.git
synced 2026-02-08 04:44:00 +08:00
Create 线性表动态初始化
This commit is contained in:
29
线性表/线性表动态初始化
Normal file
29
线性表/线性表动态初始化
Normal file
@@ -0,0 +1,29 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#define InitSize 10
|
||||
|
||||
typedef struct{
|
||||
int *data;
|
||||
int MaxSize;
|
||||
int length;
|
||||
}SeqList;
|
||||
void InitList(SeqList *L){
|
||||
L->data = (int*)malloc(sizeof(int)*InitSize);
|
||||
L->length = 0;
|
||||
L->MaxSize = InitSize;
|
||||
}
|
||||
void IncreaseSize(SeqList *L,int len){
|
||||
int *p = L->data;
|
||||
L->data = (int*)malloc(sizeof(int)*(InitSize+len));
|
||||
for(int i = 0;i < L->length;i ++){
|
||||
L->data[i] = p[i];
|
||||
}
|
||||
L->MaxSize = L->MaxSize + len;
|
||||
free(p);
|
||||
}
|
||||
int main(){
|
||||
SeqList *L;
|
||||
InitList(L);
|
||||
IncreaseSize(L,5);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user