#include<iostream>
using namespace std;
#define MAXSIZE 30
struct List{
int array[MAXSIZE];
int length;
};//定义结构体
void display(List *pl)
{
for(int i=0;i<pl->length;i++)
cout<<pl->array[i]<<",";
cout<<"size:"<<pl->length<<endl;
}//显示函数
void Init(List *pl,int n)
{
for(int i=0;i<n;i++)
{
pl->array[i]=i+10;
}
pl->length=n;
}//初始化函数
void insert(List *pl,int n,int x)
{
for(int i=pl->length-1;i>=n;i--)
pl->array[i+1]=pl->array[i];
pl->array[i+1]=x;
pl->length++;
}//插入单元函数
void del(List *pl,int n)
{
for(int i=n;i<pl->length-1;i++)
pl->array[i]=pl->array[i+1];
pl->length--;
}//删除单元函数
int size(List *pl)
{
return pl->length;
}//计算长度函数
void sortlist(List *pl)
{
for(int j=0;j<pl->length-1;j++)
for(int i=j+1;i<pl->length;i++)
if(pl->array[i]<pl->array[j])
{
int temp=pl->array[i];
pl->array[i]=pl->array[j];
pl->array[j]=temp;
}
}//冒泡排序函数
int main()
{
//初始化并显示
List* p=(List*)malloc(sizeof(List));
Init(p,10);
cout<<"初始化并显示:"<<endl;
display(p);
//插入
insert(p,3,77);
cout<<"插入:insert(p,3,77);"<<endl;
display(p);
//删除
del(p,5);
cout<<"删除:del(p,5);"<<endl;
display(p);
//冒泡排序
sortlist(p);
cout<<"冒泡排序:sortlist(p);"<<endl;
display(p);
return 0;
}