代码拉取完成,页面将自动刷新
test.c
#define _CRT_SECURE_NO_WARNINGS 1
#include"SeqList.h"
void SeqListTest1()
{
SL S1;
SeqListInit(&S1);
SeqListPushBack(&S1,1);
SeqListPushBack(&S1, 2);
SeqListPushBack(&S1, 3);
SeqListPushBack(&S1, 4);
SeqListPushBack(&S1, 5);
SeqListPrint(&S1);
}
int main()
{
SeqListTest1();
}
SeqList.c
#define _CRT_SECURE_NO_WARNINGS 1
#include"SeqList.h"
void SeqListInit(SL* ps)
{
ps->a = NULL;
ps->size = ps->capatify = 0;
}
void SeqListPushBack(SL* ps,SLDataType x)
{
if (ps->size == ps->capatify)
{
int newcapatify = ps->capatify == 0 ? 4 : ps->capatify * 2;
SLDataType* tmp = (SLDataType*)realloc(ps->a, newcapatify * sizeof(SLDataType));
if (tmp == NULL)
{
printf("realloc fail\n");
exit(-1);
}
ps->a = tmp;
ps->capatify = newcapatify;
}
ps->a[ps->size] = x;
ps->size++;
}
void SeqListPrint(SL* ps)
{
for (int i = 0; i < ps->size; ++i)
{
printf("%d ", ps->a[i]);
}
printf("\n");
}
void SeqDestory(SL* ps)
{
free(ps->a);
ps->a = NULL;
}
SeqList.h
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#pragma once
#define N 1000
typedef int SLDataType;
typedef struct SeqList
{
SLDataType* a;
int size;
int capatify;
}SL;
void SeqListInit(SL* ps);
void SeqListPushBack(SL* ps);
void SeqListPrint(SL* ps);
void SeqDestory(SL* ps);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。