資源簡介
(1)編寫順序表基本操作函數
① 初始化線性表void InitList(List *L,int ms)
② 向順序表指定位置插入元素void InsertList(List *L,int item, int rc)
③ 刪除指定元素值的順序表記錄void DeletList1(List *L, int item)
④ 刪除指定位置的順序表記錄void DeletList2(List *L,int rc)
⑤ 查找順序表中的元素void FindList(List *L, int item)
⑥ 輸出順序表元素void OutputList(List *L)
代碼片段和文件信息
#define?LIST_INIT_SIZE?10
#define?LISTINCREMENT?2
#include?
#include?
#include?
typedef?struct?LinearList
{
int*?list;
int?size;
int?MAXSIZE;
}List;
void?InitList(List*?Lint?ms)
{
L->list=(int*)malloc(LIST_INIT_SIZE*sizeof(int));
if?(!L->list)
exit(1);
L->size=0;
L->MAXSIZE=LIST_INIT_SIZE;
}
void?InsertList(List*?Lint?itemint?rc)
{
int?i;
if?(rc<1?||?rc>L->size+1)
{
exit(1);
}
if?(L->size>=L->MAXSIZE)
{
L->list=(int*)realloc(L->list(L->MAXSIZE+LISTINCREMENT)*sizeof(int));
if?(!L->list)
{
exit(1);
}
L->MAXSIZE+=LISTINCREMENT;
}
for?(i=L->size-1;i>=rc-1;i--)
{
L->list[i+1]=L->list[i];
}
L->list[rc-1]=item;
L->size++;
}
void?DeleteList1(List*?Lint?item)
{
int?ij;
for?(i=0;i
評論
共有 條評論