顺序表属于顺序存储结构,其逻辑次序与存储位置的物理次序一致,物理位置反映逻辑关系,按位置随机存取是其最大的特点。结构组成如下:
#define MAXSIZE 100
typedef struct list{
int array[MAXSIZE];
int last;
}SeqList;
last记录当前顺序表中最后一个元素在数组中的位置,即数组下标。顺序表长度为last+1。
插入代码如下:时间复杂度O(n)
#include "stdio.h"
#define MAXSIZE 50
typedef struct SeqList{
int array[MAXSIZE];
int last;
}Seqlist;
void Insert(Seqlist L,int x,int y){
int i,j;
if(y<=0||y>L.last+1)
printf("插入位置错误\n");
else{
for(i=L.last;i>y-2