DS顺序表--连续操作
程序员文章站
2022-05-08 09:23:36
...
#include<iostream>
using namespace std;
// 顺序表类定义
class seqlist
{
private:
int *list;
int maxsize;
int size;
public:
seqlist();
~seqlist();
void creat(int *p, int size_num)
{
int i;
size = size_num;
for(i = 0; i < size; i++)
{
list[i] = p[i];
}
list_display();
}
int list_size()
{
return size;
}
void multiinsert(int i, int n, int *p)
{
int j;
for(j = size-1; j >= i-1; j--)
{
list[j+n] = list[j];
}
for(j = 0; j < n; j++)
{
list[i-1+j] = p[j];
}
size += n;
list_display();
}
void multidel(int i, int n)
{
int j;
for(j = 0; j < n; j++)
{
list[j+i-1] = list[j+i+-1+n];
}
size -= n;
list_display();
}
void list_display()
{
int i;
cout << list_size() << " ";
for(i = 0; i < size; i++)
cout << list[i] << " ";
cout << endl;
}
};
seqlist::seqlist()
{
maxsize = 1000;
size = 0;
list = new int [maxsize];
}
seqlist::~seqlist()
{
delete []list;
}
int main()
{
int size, i, loc, n;
cin >> size;
seqlist l;
int *arr = new int [size];
for(i = 0; i < size; i++)
{
cin >> arr[i];
}
l.creat(arr, size);
delete []arr;
cin >> loc >> n;
arr = new int [n];
for(i =0 ; i < n; i++)
{
cin >> arr[i];
}
l.multiinsert(loc, n, arr);
delete []arr;
cin >> loc >> n;
l.multidel(loc, n);
return 0;
}
样例输入
6 11 22 33 44 55 66
2 3 99 88 77
4 5
样例输出
6 11 22 33 44 55 66
9 11 99 88 77 22 33 44 55 66
4 11 99 88 66
上一篇: 芯片缺货将持续到2022年 AMD/NVIDIA显卡不好买
下一篇: mybatis配置文件