一、顺序表结构定义
#define INIT_SIZE 10 ///< 顺序表初始容量
typedef int seqType; ///< 定义顺序表元素类型
/// @brief 顺序表结构定义
typedef struct t_sqList
{
seqType* pbase; ///< 表基址
int capacity; ///< 表容量
int size; ///< 表长度
}mySList;
二、初始化顺序表
/// @param[in] plist:表结构指针
/// @param[in] capacity:指定表初始化容量,若小于1,则为INIT_SIZE
/// @return status:返回初始化结果
/// @retval ERROR(0):顺序表不存在,不可操作
/// @retval OK(1):初始化成功
status sList_init(mySList* plist, int capacity)
{
if (plist == NULL)
{
return ERROR;
}
if (capacity < 1)
{
capacity = INIT_SIZE;
}
seqType* pbase = (seqType*)malloc(sizeof(seqType) * capacity);
if (NULL == pbase)
{
return ERR_OVERFLOW;
}
plist->size = 0;
plist->capacity = capacity;
plist->pbase = pbase;
return OK;
}
标签:初始化,pbase,顺序,capacity,seqType,plist
From: https://www.cnblogs.com/kxwslmsps/p/17121743.html