#include<iostream>;
using namespace std;
#define MAXSIZE 100
typedef int ElemType;
typedef struct {
ElemType* data;
int length;
}SqList;
void CreatList(SqList& L) {
L.data = (ElemType*)malloc(MAXSIZE*sizeof(ElemType));//注意数组也要分配空间
cin >> L.length;
for (int i = 0; i < L.length; ++i)
cin >> L.data[i];
}
void Insert_Sq(SqList& L, ElemType e) {
int i;
for (i = L.length - 1; i >= 0 && L.data[i] > e; i--) {
L.data[i + 1] = L.data[i];
}
L.data[i + 1] = e;
L.length++;
}
void Show(SqList L) {
for (int i = 0; i < L.length; i++)
cout << L.data[i] << " ";
cout << endl;
}
void main() {
SqList L;
CreatList(L);
ElemType e;
cin >> e;
Insert_Sq(L, e);
Show(L);
}
数据结构NOJ——01顺序表的插入运算
最新推荐文章于 2024-08-16 08:54:14 发布