標頭檔案:
#pragma once
#include
#include
#include
#include
typedef
int sldatetype;
//資料
typedef
struct seqlist
seqlist;
// 對資料的管理:增刪查改
void
seqlistinit
(seqlist* ps)
;//初始化
void
seqlistdestory
(seqlist* ps)
;//銷毀
void
seqlistprint
(seqlist* ps)
;//列印
void
seqlistpushback
(seqlist* ps, sldatetype x)
;//尾插
void
seqlistpushfront
(seqlist* ps, sldatetype x)
;//頭插
void
seqlistpopfront
(seqlist* ps)
;//頭刪
void
seqlistpopback
(seqlist* ps)
;//尾刪
intseqlistfind
(seqlist* ps, sldatetype x)
;//查詢
// 順序表在pos位置插入x
void
seqlistinsert
(seqlist* ps, size_t pos, sldatetype x)
;// 順序表刪除pos位置的值
void
seqlisterase
(seqlist* ps, size_t pos)
;
測試部分:
#include
"seqlist.h"
void
seqlistinit
(seqlist* ps)
//初始化
void
seqlistdestory
(seqlist* ps)
//銷毀
void
seqlistprint
(seqlist* ps)
//列印
printf
("%\n");
}void
checkcacpity
(seqlist* ps)
//核對容量大小,不夠了在realloc
}void
seqlistpushback
(seqlist* ps, sldatetype x)
//尾插
void
seqlistpushfront
(seqlist* ps, sldatetype x)
//頭插
ps->a[0]
= x;
++ps->size;*/
//seqlistinsert(ps, 0, x); 也可以用任意插函式
}void
seqlistpopfront
(seqlist* ps)
//頭刪
size_t start =1;
while
(start < ps->size)
--ps->size;
// seqlisterase(ps, 0); 也可以用任意刪函式
}void
seqlistpopback
(seqlist* ps)
//尾刪
void
seqlistfind
(seqlist* ps, seqdatatype x)
//查詢
}printf
("查詢的資料不存在\n");
}// 順序表在pos位置插入x
void
seqlistinsert
(seqlist* ps, size_t pos, sldatetype x)
size_t end = ps->size ;
while
(end > pos)
ps->a[pos]
= x;
ps->size++;}
// 順序表刪除pos位置的值
void
seqlisterase
(seqlist* ps, size_t pos)
size_t start = pos+1;
while
(start < ps->size)
ps->size--
;}
主函式:
#include
"test.h"
test
(seqlist *s)
intmain()
順序表的動態儲存
靜態順序表 使用定長陣列儲存。動態順序表 使用動態開闢的陣列儲存。順序表的靜態儲存 define n 100 typedef int sldatatype typedef struct seqlist seqlist 順序表的動態儲存 typedef struct seqlist seqlist 這...
DS線性表的順序儲存 順序表 靜態陣列 動態分配
線性表的基本操作 initlist l 初始化表,構造1個空的線性表 listinsert l,i,e 插入操作,在表l的第i個位置插入指定元素e listdelete l,i,e 刪除操作,刪除表中第i個位置的元素,並用e返回刪除元素的值 getelem l,i 按位查詢操作,獲取表中第i個位置上...
動態順序表
ifndef seqlist h define seqlist h define capacity 3 typedef struct seqlist typedef enum tag typedef struct findret void expendseqlist seqlist pseq 擴大容...