#include "pch.h"
#include<stdio.h>
#include<malloc.h>
#define now_size 100
#define add_size 10
typedef struct
{
int c[now_size]; //存储空间基值
int length; //当前长度
int listsize;//当前容量
}sqlist;// 结构体 sqlist
int initlist(sqlist*&L)//创建动态空表
{
L = (sqlist *)malloc(add_size * sizeof(sqlist)); //分配存放线性表的空间
L->length = 0;
return 0;
}
int createlis(sqlist *&L, int a[], int n)//赋值表
{
int i;
for (i = 0; i < n; i++)
{
L->c[i] = a[i];
}
L->length = n;
return 0;
}
int delist(sqlist *&L, int x, int y)//删除X-Y的范围数字
{
int k = 0;
for (int i = 0; i < L->length; i++)
{
if (L->c[i] >= x && L->c[i] <= y)
k++;
else
L->c[i - k] = L->c[i];
}
L->length -= k;
return 0;
}
int show_list(sqlist *&L)//打印表
{
for (int i = 0; i < L->length; i++)
{
printf("%d\t", L->c[i]);
}
return 0;
}
int listinsert(sqlist *&L,int e)//将数据e插入
{
int i;
for (int r = 0; r < L->length; r++)
{
if (e < L->c[r])
{
i = r;
L->length += 1;
break;
}
}
int t;
t = L->c[i];
L->c[i] = e;
for (int r=i;r<L->length;r++)
{
int p = L->c[r + 1];
L->c[r + 1] =t;
t = p;
}
return true;
}
int main(int)
{
int a[] = { 1,2,3,5,6,7,8,9 };
int x = 5, y = 7;
sqlist *L;
initlist (L);
int n=sizeof(a)/4;
createlis(L, a, n);
//delist(L, x, y);
listinsert(L, 4);
printf("\nL:");
show_list(L);
}