前言
用C语言实现顺序表的基本操作。
提示:以下是本篇文章正文内容,下面案例可供参考
一、顺序表
数据结构C语言版的顺序表
二、使用步骤
1.基本操作代码
代码如下(示例):
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define ERROR -1
#define OK 0
#define INCREMENT 10//增量
#define LISTSIZE 100//初始空间
typedef int Status;
typedef int Elemtype;
//顺序存储结构
typedef struct {
Elemtype *elem;
int length;
int listsize;
}SqList;
//初始化
Status InitSqList(SqList &L){
L.elem=(Elemtype*)malloc(LISTSIZE*sizeof(Elemtype));
if(!L.elem){
return ERROR;
}
L.length=0;
L.listsize=LIS