当前位置: 编程技术>c/c++/嵌入式
C语言实现顺序表基本操作汇总
来源: 互联网 发布时间:2014-10-26
本文导语: 本文汇总了C语言下实现及操作顺序表的方法,对于学习数据结构的朋友来说是一个不错的参考程序。完整代码如下: #include #include #define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define OVERFLOW -2 #define LIST_INIT_SIZE 100 #def...
本文汇总了C语言下实现及操作顺序表的方法,对于学习数据结构的朋友来说是一个不错的参考程序。完整代码如下:
#include
#include
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef int status ;
typedef int ElemType ;
typedef struct{
ElemType *elem;
int length,listsize;
}SqList;
status InitList(SqList &L)//初始化
{
L.elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L.elem) exit(OVERFLOW);
L.listsize=LIST_INIT_SIZE;
L.length=0;
return OK;
}
status Build(SqList &L)//建立表
{
int i,n;
printf("请输入元素个数n和n个元素n");
scanf("%d",&n);
if(n>LIST_INIT_SIZE)//如果n大于当前空间
{
L.elem=(ElemType *)realloc(L.elem,(n+LISTINCREMENT)*sizeof(ElemType));
if(!L.elem) exit(OVERFLOW);
L.listsize=n+LISTINCREMENT;
}
for(i=0;i