1、线性表的创建与插入操作;
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef int type;
int len1=100,len2=10;// 初始变量;
struct node{
type *elem; // 基地址;
int len;// 当前长度;
int size;//分配的存储空间大小;
}sq;
void build()//建立空链表;
{
sq.elem=(type *)malloc(len1*sizeof(type));// 申请空间;
if(!sq.elem) // 检测(一般不会出错);
{
printf("error");
exit(1);
}
sq.len=0;// 申请成功,初始化;
sq.size=len1;
return ;
}
void init(int i,int x)
{
if(i<1||i>sq.size+1) return ;// 插入不合法;
if(sq.len>=sq.size) //如果当前的空间已满;
{
type *newbase=(type *)realloc(sq