1 Star 0 Fork 0

CoderQi/cg初学

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SeqList.c 958 Bytes
一键复制 编辑 原始数据 按行查看 历史
CoderQi 提交于 2022-12-25 20:48 +08:00 . 1225
#include "SeqList.h"
void Seqlistprint(SL* ps)
{
for (int i = 0; i < ps->size; i++)
{
printf("%d ", ps->a[i]);
}
printf("\n");
}
void SeqListinit(SL *ps)
{
ps->a = NULL;
ps->size = ps->capacity = 0;
}
void SeqListinit(SL* ps)
{
free(ps->a);
ps->a = NULL;
ps->capacity = ps->size = 0;
}
void SeqListpushback(SL* ps, SLDataType x)//尾插
{
if (ps->size == ps->capacity)//没有空间或者满了则扩容
{
int newcapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;//0的话是4,非零*2;
SLDataType* tmp = realloc(ps->a, newcapacity * sizeof(SLDataType));
if (tmp == NULL)
{
printf("realloc fail\n");
exit(-1);
}
//开空间成功了
ps->a = tmp;
ps->capacity = newcapacity;
}
ps->a[ps->size] = x;//在尾部插入数据
ps->size++;
}
void SeqListpopback(SL* ps)//尾删
{
ps->a[ps->size - 1] = 0;
ps->size--;
}
void SeqListpushfront(SL* ps, SLDataType x);
void SeqListpopfront(SL* ps);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/programmercg/cg-beginner.git
git@gitee.com:programmercg/cg-beginner.git
programmercg
cg-beginner
cg初学
master

搜索帮助