#include <stdio.h>
#include <stdlib.h>
typedef int DataType; /*数据类型*/
typedef int ElemType; /*元素类型*/
//--------------线性表的动态顺序存储结构------------
#define LIST_INIT_SIZE 100 //线性表存储空间的初始分配量
#define LISTINCREMENT 10 //线性表存储空间的分配增量
typedef struct
{
ElemType *elem; //存储空间基址
int length; //当前长度
int listsize; //当前分配的存储容量
}SqList;
void InitList(SqList *L)
//初始化
{
L->elem = (ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));//分配空间
L->length = 0; //空表的长度为0
L->listsize = LIST_INIT_SIZE; //初始容量
}
void CreateList(SqList *L, int n)
{
InitList(L); //初始化
int i;
for(i = 0; i < n; i ++)
{
scanf("%d", &L->elem[i]);
L->length++;
}
}
void InsertList(SqList *L, int e)
{
int i;
//从顺序表最后一位开始,将所有大于e的元素向后移动
for(i = L->length-1; L->elem[i] > e; i--)
{
L->elem[i+1] = L->elem[i];
}
//插入之
L->elem[i] = e;
L->length++;
}
void ListTraverse(SqList *L)
{
int n = L->length, i;
for(i = 0; i < n; i++)
printf("%d\n", L->elem[i]);
}
int main()
{
SqList L;
int n;
scanf("%d", &n);
CreateList(&L, n);
int e;
scanf("%d", &e);
InsertList(&L, e);
ListTraverse(&L);
return 0;
}
慕哥9229398
jeck猫
慕田峪4524236