1-有界数组模版类
#include<iostream>
using namespace std;
template<class TYPE>
class BoundArray {
TYPE* a;
int size;
public:
BoundArray(int length) {
size = length;
a = new TYPE[length];
for (int i = 0; i < length; i++)
cin >> a[i];
}
void sort() {
for (int i = 0; i < size; i++) {
for (int j = i; j < size; j++) {
if (a[i] > a[j]) {
TYPE t = a[j];
a[j] = a[i];
a[i] = t;
}
}
}
}
void show() { for (int i = 0; i < size; i++) cout << a[i] << " "; cout << endl; }
int search(TYPE p) {
int flag = -1;
for (int i = 0; i < size; i++) {
if (a[i] == p) { flag = i; break; }
}
return flag;
}
};
int main() {
int t;
cin >> t;
while (t--) {
char TYPE;
int size;
cin >> TYPE >> size;
if (TYPE == 'I') {
int x;
BoundArray<int>p(size);
cin >> x;
p.sort();
p.show();
cout << p.search(x) << endl;
}
else if (TYPE == 'D') {
double x;
BoundArray<double>p(size);
cin >> x;
p.sort();
p.show();
cout << p.search(x) << endl;
}
else if (TYPE == 'C') {
char x;
BoundArray<char>p(size);
cin >> x;
p.sort();
p.show();
cout << p.search(x) << endl;
}
}
}
2-简单类模版
#include<iostream>
using namespace std;
template<class TYPE>
class table {
TYPE p[100];
int size;
public:
table(int length) {
size = length;
for (int i = 0; i < length; i++) cin >> p[i];
for (int i = length; i < 100; i++) p[i] = -1;
}
void insert(int location,TYPE num) {
for (int i = size ; i > location; i--) {
p[i] = p[i - 1];
}
p[location] = num;
size += 1;
}
void destory(int location) {
for (int i = location; i < size - 1; i++) p[i] = p[i + 1];
p[size - 1] = -1;
size -= 1;
}
void print() {
for (int i = 0; i < size-1; i++) {
cout << p[i] << " ";
}
cout << p[size - 1]<<endl;
}
};
int main() {
int size;
cin >> size;
table <int>t(size);
int location, x;
cin >> location >> x;
t.insert(location, x);
cin >> location;
t.destory(location);
t.print();
cin >> size;
table<double>t1(size);
double y;
cin >> location >> y;
t1.insert(location, y);
cin >> location;
t1.destory(location);
t1.print();
}
3-矩阵类模版
#include<iostream>
using namespace std;
template<class TYPE>
class Matrix {
TYPE **p;
int m;
int n;
public:
Matrix(int m1, int n1) {
m = m1, n = n1;
p = new TYPE * [m1];
for (int i = 0; i < m1; i++) p[i] = new TYPE[n1];
for (int i = 0; i < m1; i++) {
for (int j = 0; j < n1; j++)
cin >> p[i][j];
}
}
void transport() {
TYPE** t;
t = new TYPE * [m];
for (int i = 0; i < m; i++) t[i] = new TYPE[n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++)
t[i][j] = p[i][j];
}
p = new TYPE * [n];
for (int i = 0; i < n; i++) p[i] = new TYPE[m];
int x = m;
m = n;
n = x;
for (int i = 0; i < m; i++){
for (int j = 0; j < n;j++)
p[i][j] = t[j][i];
}
delete[]t;
}
void print() {
for (int i = 0; i < m; i++) {
for(int j=0;j<n-1;j++)
cout<<p[i][j]<<" ";
cout<<p[i][n-1]<<endl;
}
}
};
int main() {
int t;
cin >> t;
while (t--) {
char type;
int m, n;
cin >> type >> m >> n;
switch (type) {
case 'I':{
Matrix<int> M(m, n);
M.transport();
M.print();
break;
}
case'D':{
Matrix<double> M(m, n);
M.transport();
M.print();
break;
}
case 'C': {
Matrix<char> M(m, n);
M.transport();
M.print();
break;
}
}
}
}
4-排序函数模板
#include<iostream>
#include<cstring>
#include<cmath>
#include<iomanip>
using namespace std;
class point {
double x;
double y;
public:
point() { x = 0; y = 0; }
point(double x1, double y1) :x(x1), y(y1) {}
void setxy(double x1, double y1) {
x = x1;
y = y1;
}
friend bool operator>(point& p1, point& p2) {
return sqrt(p1.x * p1.x + p1.y * p1.y) > sqrt(p2.x * p2.x + p2.y * p2.y);
}
friend ostream& operator<<(ostream& stream, point& p) {
stream << "(" << fixed << setprecision(1) << p.x << "," << " " << fixed << setprecision(1) << p.y << ")";
return stream;
}
};
template<class TYPE>
void mysort(TYPE* t1, int m) {
TYPE t;
for (int i = 0; i < m; i++) {
for (int j = i + 1; j < m; j++) {
if (t1[i] > t1[j]) {
t = t1[i];
t1[i] = t1[j];
t1[j] = t;
}
}
}
};
template<class TYPE>
void myprint(TYPE* t, int m) {
for (int i = 0; i < m; i++) {
cout << t[i] << " ";
}
cout << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
char type;
int m;
cin >> type >> m;
if (type == 'I') {
int* a = new int[m];
for (int i = 0; i < m; i++)
{
cin >> a[i];
}
mysort<int>(a, m);
myprint<int>(a, m);
}
else if (type == 'D') {
double* a = new double[m];
for (int i = 0; i < m; i++)
{
cin >> a[i];
}
mysort<double>(a, m);
myprint<double>(a, m);
}
else if (type == 'S') {
string* a = new string[m];
for (int i = 0; i < m; i++)
{
cin >> a[i];
}
mysort<string>(a, m);
myprint<string>(a, m);
}
else if (type == 'P') {
double x, y;
point* p = new point[m];
for (int i = 0; i < m; i++) {
cin >> x >> y;
(p + i)->setxy(x, y);
}
mysort(p, m);
myprint(p, m);
}
}
}
5-对象相加函数模板
#include<iostream>
#include<cstring>
#include<cmath>
#include<iomanip>
using namespace std;
class CClock {
int hour;
int minute;
int second;
public:
CClock() { hour = 0; minute = 0; second = 0; }
CClock(int h, int m, int s) :hour(h), minute(m), second(s) {}
int getx() { return hour; }
int gety() { return minute; }
int getz() { return second; }
};
class CRmb {
int yuan;
int fen;
int jiao;
public:
CRmb() { yuan = 0; jiao = 0; fen = 0; }
CRmb(int y, int j, int f) {
yuan = y;
jiao = j;
fen = f;
}
int getx() { return yuan; }
int gety() { return jiao; }
int getz() { return fen; }
};
template <class T>
T add(T& t1, T& t2, int m) {
int a, b, c;
c = (t1.getz() + t2.getz()) % m;
b = (t1.gety() + t2.gety() + (t1.getz() + t2.getz())/m) % m;
a= (t1.getx() + t2.getx() + (t1.gety()+t2.gety()+ (t1.getz() + t2.getz())/m)/m) % m;
T t(a,b,c);
return t;
}
template <class T>
void print(T& t) {
cout << t.getx() <<" " <<t.gety() << " " << t.getz() << endl;
}
int main() {
int hour1, hour2, minute1, minute2, second1, second2;
int yuan1, yuan2, jiao1, jiao2, fen1, fen2;
cin >> hour1 >> minute1 >> second1 >> hour2 >> minute2 >> second2;
cin >> yuan1 >> jiao1 >> fen1 >> yuan2 >> jiao2 >> fen2;
CClock c1(hour1, minute1, second1), c2(hour2, minute2, second2), c;
c = add(c1, c2, 60);
print(c);
CRmb r1(yuan1, jiao1, fen1), r2(yuan2, jiao2, fen2), r;
r = add(r1, r2, 10);
print(r);
}
6-逆序输出函数模板
#include<iostream>
#include<cstring>
#include<cmath>
#include<iomanip>
using namespace std;
class complax{
int real;
int image;
public:
complax() { real = 0; image = 0; }
complax(int r,int i):image(i),real(r){}
void change() {
int t = real;
real = image;
image = t;
}
void show() {
if (image > 0)
cout << real << "+" << image << endl;
else
cout << real << image << endl;
}
};
class typeint {
int n;
public:
typeint() { n = 0; }
typeint(int x) { n = x; }
void change() {
int b = 0;
while (n) {
b = b * 10 + n % 10;
n = n / 10;
}
n = b;
}
void show() { cout << n << endl; }
};
class typedouble {
char* d;
public:
typedouble() { d = 0; }
typedouble(char* x) { d = new char[sizeof(x) + 1]; strcpy(x, d); }
void change() {
int flag = 1;
if (*d == '-') flag = 0;
int i = 0, j = 0;
for (int k = 0; k < sizeof(d); k++) {
if (*(d + k) == '.') break;
if (*(d + k) != '-') i++;
}
j = sizeof(d) - i - 1 - flag;
char* d1 = new char[i + 1], * d2 = new char[j + 1];
int l = 0;
for(int k = 0; *(d + k) != '.'; k++) {
if (*(d + k) != '-') *(d1 + (l++)) = *(d + k);
}
l = 0;
for (int k = i + 1; k < sizeof(d); k++) {
if (*(d + k) != '.') *(d2 + (l++)) = *(d + k);
}
char* d3 = new char[i];
for (int k = 0; k < i; k++)
d3[k] = d1[i - 1 - k];
strcpy(d1, d3);
d3 = new char[j];
for (int k = 0; k < j; k++)
d3[k] = d1[j - 1 + k];
strcpy(d2, d3);
if (!flag) {
char* p = new char[i + j + 2];
p[0] = '-';
l = 1;
for (int k = 0; k < i; k++) {
p[l++] = d1[k];
}
p[i] = '.';
l += 1;
for (int k = 0; k < j; k++)
p[l++] = d2[k];
strcpy(d, p);
}
else
{
char* p = new char[i + j + 1];
l = 0;
for (int k = 0; k < i; k++)
p[l++] = d1[k];
p[i] = '.';
l += 1;
for (int k = 0; k < j; k++)
p[l++] = d2[k];
strcpy(d, p);
}
}
void show() {
for (int i = 0; i < sizeof(d); i++)
cout << *(d + i);
cout << endl;
}
};
class typestring {
char *s;
public:
typestring() { s = NULL; }
typestring(char* p) {
s = new char[sizeof(p) + 1];
strcpy(s, p);
}
void change() {
char* s1;
s1 = new char[sizeof(s1) + 1];
strcpy(s1, s);
s1 = new char[sizeof(s) + 1];
for (int i = 0; i < sizeof(s); i++) {
s[sizeof(s) - 1-i] = s1[i];
}
}
void show() {
for (int i = 0; i < sizeof(s); i++)
cout << *(s + i);
cout << endl;
}
};
template<class T>
void reverse(T& t) {
t.change();
t.show();
}
int main() {
int t;
char type;
cin >> t;
while (t--) {
cin >> type;
if (type == 'I') {
int x;
cin >> x;
typeint II(x);
reverse(II);
}
else if (type == 'D') {
char* x;
cin >> *x;
typedouble dd(x);
reverse(dd);
}
else if (type == 'S') {
char* s;
cin >> s;
typestring ss(s);
reverse(s);
}
else if (type == 'C') {
int real, image;
cin >> real >> image;
complax C(real, image);
reverse(C);
}
}
}
7-链表类模板
//当时没时间写
#include<iostream>
#include<algorithm>
using namespace std;
template<typename T>
class CBArr
{
private:
T *dat;
int len;
public:
CBArr(int l): len(l){
dat=new T[len];
for(int i=0; i<len; ++i)
cin>>dat[i];
}
~CBArr(){
delete []dat;
}
void Sort(){
sort(dat, dat+len);
}
int search(T val){
for(int i=0; i<len; ++i)
if(dat[i]==val)
return i;
return -1;
}
void print(){
for(int i=0; i<len; ++i)
cout<<dat[i]<<" ";
cout<<endl;
}
T& operator[](int pos){
if(pos<0 || pos>len-1){
cout<<"数组下标越界"<<endl;
exit(0);
}
return dat[pos];
}
};
int main()
{ int t, len;
char type;
cin>>t;
while(t--)
{
cin>>type>>len;
if(type=='I'){
CBArr<int> x(len);
x.Sort();
x.print();
int val;
cin>>val;
cout<<x.search(val)<<endl;
}
if(type=='D'){
CBArr<double> x(len);
x.Sort();
x.print();
double val;
cin>>val;
cout<<x.search(val)<<endl;
}
if(type=='C'){
CBArr<char> x(len);
x.Sort();
x.print();
char val;
cin>>val;
cout<<x.search(val)<<endl;
}
}
return 0;
}
==============================================================
#include<iostream>
using namespace std;
template <class TYPE>
class List{
private:
TYPE a[100];
int len;
public:
List(int n=1):len(n){
for(int i=0;i<len;i++)
cin>>a[i];
}
void insert(TYPE value,int index){
for(int i=len-1;i>=index;i--)
a[i+1]=a[i];
a[index]=value;
len++;
}
void Delete(int index){
for(int i=index+1;i<len;i++)
a[i-1]=a[i];
len--;
}
void show(){
for(int i=0;i<len-1;i++)
cout<<a[i]<<" ";
cout<<a[len-1]<<endl;
}
};
int main()
{ int n,value1,index;
float value2;
cin>>n;
List<int> l1(n);
cin>>index>>value1;
l1.insert(value1,index);
cin>>index;
l1.Delete(index);
l1.show();
cin>>n;
List<float> l2(n);
cin>>index>>value2;
l2.insert(value2,index);
cin>>index;
l2.Delete(index);
l2.show();
}
==============================================================
#include<iostream>
using namespace std;
template<class T>
class Matrix
{
private:
T **array;
int m, n;
public:
Matrix(int m1, int n1):m(m1),n(n1){
array=new T*[m];
for(int i = 0; i < m; i++){
array[i]=new T[n];
for(int j = 0; j < n; j++)
cin>>array[i][j];
}
}
void transport(){
T **array2=array;
int i, j;
array=new T*[n];
for(i = 0 ; i < n; i++){
array[i]=new T[m];
for(j = 0; j < m; j++)
array[i][j] = array2[j][i];
}
for(int i=0;i<m;i++)
delete[] array2[i];
delete[] array2;
int t;
t = m;
m = n;
n = t;
}
void print(){
int i,j;
for(i = 0; i < m; i++){
for(j = 0; j < n-1; j++)
cout <<array[i][j]<<" ";
cout << array[i][j]<<endl;
}
}
~Matrix(){
for(int i=0;i<m;i++)
delete[] array[i];
delete[] array;
}
};
int main()
{ int t;
cin >> t;
while(t--){
int m, n;
char c;
cin >> c>> m >> n;
if(c == 'I'){
Matrix<int> M(m, n);
M.transport();
M.print();
}
if(c == 'D'){
Matrix<double> M(m, n);
M.transport();
M.print();
}
if(c == 'C'){
Matrix<char> M(m, n);
M.transport();
M.print();
}
}
return 0;
}
==============================================================
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
class CPoint {
double x,y;
public:
CPoint(int x1=0,int y1=0):x(x1),y(y1){}
friend ostream& operator << (ostream &o,const CPoint &p) {
o<<"("<<fixed<<setprecision(1)<<p.x<<", "<<p.y<<")";
return o;
}
friend istream& operator >> (istream &i,CPoint &p) {
i>>p.x>>p.y;
return i;
}
bool operator >(const CPoint &p){
double d1,d2;
d1=sqrt(x*x+y*y);
d2=sqrt(p.x*p.x+p.y*p.y);
if(d1>d2)
return true;
else
return false;
}
};
template <class T>
void mysort(T *a,int n) {
int i,j;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n-1;i++)
for(j=0;j<n-1-i;j++){
if(a[j]>a[j+1]){
T temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
}
int main() {
string opr;
int t,n;
cin>>t;
while(t--){
cin>>opr>>n;
if(opr=="I"){
int *num=new int[n];
mysort(num,n);
}
else if(opr=="D"){
double *num=new double[n];
mysort(num,n);
}
else if(opr=="P"){
CPoint *num=new CPoint[n];
mysort(num,n);
}
else if(opr=="S"){
string *num=new string[n];
mysort(num,n);
}
}
return 0;
}
/
使用sort函数排序
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
using namespace std;
class CPoint {
double x,y;
public:
CPoint(int x1=0,int y1=0):x(x1),y(y1){}
friend ostream& operator << (ostream &o,const CPoint &p) {
o<<"("<<fixed<<setprecision(1)<<p.x<<", "<<p.y<<")";
return o;
}
friend istream& operator >> (istream &i,CPoint &p) {
i>>p.x>>p.y;
return i;
}
bool operator <(const CPoint& p)const{ //注意,如果在OJ上提交,必须要声明为常函数。自定义对象使用sort排序,重载<运算符
double d1,d2;
d1=sqrt(x*x+y*y);
d2=sqrt(p.x*p.x+p.y*p.y);
if(d1<d2)
return true;
else
return false;
}
};
template <class T>
void mysort(T *a,int n) {
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
}
int main() {
string opr;
int t,n;
cin>>t;
while(t--){
cin>>opr>>n;
if(opr=="I"){
int *num=new int[n];
mysort(num,n);
delete[] num;
}
else if(opr=="D"){
double *num=new double[n];
mysort(num,n);
delete[] num;
}
else if(opr=="P"){
CPoint *num=new CPoint[n];
mysort(num,n);
delete[] num;
}
else if(opr=="S"){
string *num=new string[n];
mysort(num,n);
delete[] num;
}
}
return 0;
}
==============================================================
一、函数模板带3个参数
#include <iostream>
#include<iomanip>
using namespace std;
template<class T>
void add(T p,T q,int jz)
{
int as,bs,cs;
as=p.geta()+q.geta();
bs=p.getb()+q.getb();
cs=p.getc()+q.getc();
if(cs>=jz)
{
cs-=jz;
bs++;
if(bs>=jz)
{
bs-=jz;
as++;
}
}
if(jz==60 && as>=24)
as-=24;
cout<<as<<" "<<bs<<" "<<cs<<endl;
}
class CClock
{
int a,b,c;
public:
CClock(int a,int b,int c):a(a),b(b),c(c){}
int geta(){return a;}
int getb(){return b;}
int getc(){return c;}
};
class CRmb
{
int a,b,c;
public:
CRmb(int a,int b,int c):a(a),b(b),c(c){}
int geta(){return a;}
int getb(){return b;}
int getc(){return c;}
};
int main()
{
int a,b,c;
cin>>a>>b>>c;
CClock x(a,b,c);
cin>>a>>b>>c;
CClock y(a,b,c);
add(x,y,60);
cin>>a>>b>>c;
CRmb z(a,b,c);
cin>>a>>b>>c;
CRmb w(a,b,c);
add(z,w,10);
return 0;
}
二、函数模板带2个参数,在两个类中重载运算符+
#include <iostream>
using namespace std;
template <class T>
T add(T &a,T &b) {
return a+b;
}
class CClock {
int hour,minute,second;
public:
CClock(int h,int m,int s):hour(h),minute(m),second(s){}
CClock(){}
friend ostream& operator << (ostream &o, const CClock& c){
o<<c.hour<<" "<<c.minute<<" "<<c.second;
return o;
}
CClock operator +(const CClock &c){
int h,m,s;
h=hour+c.hour;
m=minute+c.minute;
s=second+c.second;
if(s>=60)
{m++;s-=60;}
if(m>=60)
{h++;m-=60;}
if(h>=24)
{h-=24;}
return CClock(h,m,s);
}
};
class CRmb {
int yuan,jiao,fen;
public:
CRmb(int y,int j,int f):yuan(y),jiao(j),fen(f){}
CRmb(){}
friend ostream& operator << (ostream &o,CRmb const &r) {
o<<r.yuan<<" "<<r.jiao<<" "<<r.fen;
return o;
}
CRmb operator +(const CRmb &r){
int y,j,f;
y=yuan+r.yuan;
j=jiao+r.jiao;
f=fen+r.fen;
if(f>=10)
{j++;f-=10;}
if(j>=10)
{y++;j-=10;}
return CRmb(y,j,f);
}
};
int main() {
int n1,n2,n3;
int n4,n5,n6;
cin>>n1>>n2>>n3;
cin>>n4>>n5>>n6;
CClock c1(n1,n2,n3), c2(n4,n5,n6);
cout << add(c1, c2) << endl;
cin>>n1>>n2>>n3;
cin>>n4>>n5>>n6;
CRmb r1(n1,n2,n3), r2(n4,n5,n6);
cout << add(r1, r2) << endl;
return 0;
}
==============================================================
从一致性上考虑,用非模板函数重载的方式,单独为复数做一个同名函数
#include<iostream>
#include<sstream>
using namespace std;
class Complex{
double real,image;
public:
Complex(double r,double i):real(r),image(i){}
double getreal()const{return real;}
double getimage()const{return image;}
};
template<class T>
void Reverse(T t){
stringstream os; //用字符串处理逆序
string s;
os << t;
os >> s;
if(s[0]=='-'){
cout<<"-"; //处理符号位
s=s.substr(1); //得到符号以外的数据
}
int i;
for(i=s.length()-1;i>=0;i--){ //注意尾部的0,逆序时不输出。因此要找到第一个非0的位置
if(s[i]!='0')
break;
}
if(i==-1) //若数据全为0,则输出0;否则逆序输出
cout<<"0";
else{
for(int j=i;j>=0;j--)
cout<<s[j];
}
cout<<endl;
}
void Reverse(const Complex& c){
cout<<c.getimage();
if(c.getreal()>0)
cout<<"+";
cout<< c.getreal()<<endl;
}
int main() {
int t;
char ch;
cin>>t;
while(t--){
cin>>ch;
if(ch=='I') {
int a;
cin>>a;
Reverse(a);
}
else if(ch=='D') {
double a;
cin>>a;
Reverse(a);
}
else if(ch=='S') {
string a;
cin>>a;
Reverse(a);
}
else if(ch=='C') {
double r,i;
cin>>r>>i;
Complex a(r,i);
Reverse(a);
}
}
return 0;
}
==============================================================
#include <iostream>
using namespace std ;
template<class T>
class CNode
{
public:
T data;
CNode *next;
};
template<class T>
class CIntList
{
private:
CNode<T> *head;
int size;
public:
CIntList(){
head=new CNode<T>;
head->next=NULL;
size=0;
}
void append(T a) //加到链表最后
{
CNode<T> *p=head,*s;
while(p->next)
p=p->next;
s=new CNode<T>;
s->data=a;
s->next=p->next;
p->next=s;
size++;
}
void insert(T a, int n) //在第n个结点后加
{ if(n>=0 && n<=size){
CNode<T> *p=head,*s;
for(int i=0;i<n;i++)
p=p->next;
s=new CNode<T>;
s->data=a;
s->next=p->next;
p->next=s;
size++;
}
}
void remove(int n) //移除第n个结点
{
if(n>=1 && n<=size){
CNode<T> *p=head,*q;
for(int i=0;i<n-1;i++)
p=p->next;
q=p->next;
p->next=p->next->next;
size--;
delete q;
}
}
void get(int n) //返回第n个结点的数据
{
if(n>=1 && n<=size){
CNode<T> *p=head;
for(int i=0;i<n;i++)
p=p->next;
cout<<p->data<<endl;
}
else
cout<<"error"<<endl;
}
void set(T a, int n)//将第n个节点的数据改成a
{
if(n>=1 && n<=size){
CNode<T> *p=head;
for(int i=0;i<n;i++)
p=p->next;
p->data=a;
}
}
void print(){
CNode<T> *p=head->next;
while(p->next){
cout<<p->data<<" ";
p=p->next;
}
cout<<p->data<<endl;
}
~CIntList(){
CNode<T> *q;
while(head->next){
q=head->next;
head->next=head->next->next;
delete q;
}
delete head;
size=0;
}
};
int main()
{ int t,len,num;
char type;
cin>>t;
while(t--)
{
cin>>type;
if(type=='I'){
CIntList<int> x;
cin>>len;
int value;
for(int i=1;i<=len;i++){
cin>>value;
x.append(value);
}
cin>>num;
cin>>value;
x.insert(value,num);
cin>>num;
x.get(num);
cin>>num;
x.remove(num);
cin>>num;
cin>>value;
x.set(value,num);
x.print();
}
if(type=='D'){
CIntList<double> x;
cin>>len;
double value;
for(int i=1;i<=len;i++){
cin>>value;
x.append(value);
}
cin>>num;
cin>>value;
x.insert(value,num);
cin>>num;
x.get(num);
cin>>num;
x.remove(num);
cin>>num;
cin>>value;
x.set(value,num);
x.print();
}
if(type=='S'){
CIntList<string> x;
cin>>len;
string value;
for(int i=1;i<=len;i++){
cin>>value;
x.append(value);
}
cin>>num;
cin>>value;
x.insert(value,num);
cin>>num;
x.get(num);
cin>>num;
x.remove(num);
cin>>num;
cin>>value;
x.set(value,num);
x.print();
}
}
return 0;
}