以下是用c語言實現的一部分靜態順序表的一些函式
seqlist.h
#include #include #include #define seqlistmaxsize 100
typedef char seqlisttype;
typedef struct seqlist
seqlist;
void seqlistinit(seqlist* seqlist);//清空順序表
void seqlistpushback(seqlist* seqlist,seqlisttype value);//尾插
void seqlistpopback(seqlist* seqlist);//尾刪
void seqlistpushfront(seqlist* seqlist, seqlisttype value);//頭插
void seqlistpopfornt(seqlist* seqlist);//頭刪
seqlisttype seqlistread(seqlist* seqlist, size_t pos);//讀任意位置的元素
void seqlistchange(seqlist* seqlist, size_t pos,seqlisttype value);//修改任意位置元素
size_t seqlistsearch(seqlist* seqlist, seqlisttype value);//查詢指定元素值的下標
void seqlistinsert(seqlist* seqlist, seqlisttype value, size_t pos);//在任意位置插入元素seq
seqlist.c
#incldue "seqlist.h"
void seqlistinit(seqlist* seqlist)//清空順序表
seqlist->size = 0;
}void seqlistpushback(seqlist* seqlist,seqlisttype value)//尾插
if (seqlist->size == seqlistmaxsize)
seqlist->data[seqlist->size] = value;
seqlist->size++;
}void seqlistpopback(seqlist* seqlist)//尾刪
if (seqlist->size == 0)
seqlist->size--;
}void seqlistpushfront(seqlist* seqlist, seqlisttype value)//頭插
if (seqlist->size == seqlistmaxsize)
seqlist->size++;
size_t i = seqlist->size - 1;
for (; i >= 1; i--)
seqlist->data[0] = value;
}void seqlistpopfornt(seqlist* seqlist)//頭刪
if (seqlist->size == 0)
size_t i = 0;
for (; i < seqlist->size - 1; i++)
seqlist->size--;
}seqlisttype seqlistread(seqlist* seqlist, size_t pos)//讀任意位置的元素
if (seqlist->size == seqlistmaxsize)
if (pos >= seqlist->size)
return seqlist->data[pos];
}void seqlistchange(seqlist* seqlist, size_t pos,seqlisttype value)//修改任意位置的元素
if (seqlist->size == 0)
if (pos >= seqlist->size)
seqlist->data[pos] = value;
}size_t seqlistsearch(seqlist* seqlist,seqlisttype value)//查詢指定元素值的下標
if (seqlist->size == 0)
size_t i = 0;
for (; i <= seqlist->size; i++) }
return -1;
}void seqlistinsert(seqlist* seqlist, seqlisttype value, size_t pos)
if (seqlist->size == 0)
if (pos == 0)
seqlist->size++;
size_t i = seqlist->size - 1;
for (; i - 1 >= pos; i--)
seqlist->data[pos] = value;
}int main()
靜態順序表的相關操作
話不多說,直接看 include typedef int datatype define max size 10 typedef struct seqlist seqlist,pseqlist typedef struct seqlist pseqlist void seqlistinit pseq...
靜態順序表的實現
define crt secure no warnings include include include define max 10 typedef int datatype typedef struct seqlist seqlist,pseqlist void initseqlist pseq...
靜態順序表的實現
靜態順序表 實現 標頭檔案 seqlist.h pragma once define max size 10000 typedef unsigned int size t typedef int datatype 順序表元素型別 typedef struct seqlist seqlist,pseq...