代码:
#define MAXSIZE 100
#define OK 1
#define OVERFLOW -2
#include<iostream>
using namespace std;
typedef int elemtype;
typedef struct{
elemtype vec[MAXSIZE];
int last;
}sequenlist;
void listprint(sequenlist *L)
{
int i;
for(i=0;i<=(L->last );i++)
{
cout<<L->vec[i]<<" ";
}
}
int locate(sequenlist *L,int K)
{
int i;
for(i=0;i<=(L->last );i++)
{
if(K==(L->vec[i]))
{
return i;
}
}
return -1;
}
int insert(sequenlist *L,int i,int x)
{
int j;
if((L->last>=MAXSIZE-1))
{
cout<<"overflow";
return 0;
}
else
if(i<=0||i>(L->last+1))
{ cout<<"error";
return 0;
}
else{
for(j=L->last;j>=i-1;j--)
{
L->vec[j+1] = L->vec [j];
}
L->vec[i-1] = x;
L->last ++;
}
return 1;
}
int dele(sequenlist *L,int i)
{
if(i<=0||i>(L->last+1))
{
cout<<"error";
return 0;
}
else
{
for(int j=i;j<=L->last ;j++)
{
L->vec[j-1] = L->vec [j];
}
L->last --;
}
return 1;
}
void inverse(sequenlist *L)
{
int i = 0,j = L->last ;
int q = 0;
while(i<j)
{
q = L->vec[i];
L->vec[i] = L->vec[j];
L->vec[j] = q;
i++;
j--;
}
}
void order_insert(sequenlist *L,int k)
{
int i,a;
for(i=0;i<=L->last;i++)
{
if(k<(L->vec [i]))
{
a = i;break;
}
}
if(k>L->vec [L->last ])
a = L->last +1;
for(i=L->last;i>=a ;i++)
{
L->vec [i+1] = L->vec [i];
}
L->vec [a] = k;
L->last ++;
}
int main()
{
sequenlist s1={{1,3,6,10,15,21,28,36,45},8};
listprint(&s1);
return 0;
}