#include <iostream>
#include <malloc.h>
#define total 100
using namespace std;
struct z {
int s;
};
z *xx;
int n;
void insert_front(z a) {
for (int i = n ; i > 0; i--) {
//TODO
xx[i] = xx[i - 1];
}
xx[0] = a;
n++;
return;
}
void insert_at(z a, int pos) {
for (int i = n ; i > pos; i--) {
//TODO
xx[i] = xx[i - 1];
}
xx[pos] = a;
n++;
}
void insert_back(z a) {
xx[n++] = a;
}
void output() {
cout << endl;
for (int i = 0; i < n; i++) {
//TODO
cout << i << " " << xx[i].s << endl;
}
}
int main() {
xx = (z*)malloc(sizeof(z) * total);
xx[0].s = 0;
xx[1].s = 1;
n = 2;
z b;
b.s = -1;
output();
insert_front(b);
output();
insert_at(b, 1);
output();
insert_back(b);
output();
return 0;
}
线性表不同位置的插入、输出
最新推荐文章于 2024-10-05 12:07:50 发布