#include
using
namespace
std;
const
int maxsize = 20;
template
class sqlist;
template
sqlist::sqlist()
template
sqlist::~sqlist()
template
void sqlist::creatlist(t a, int n)
length = n;
cout
<<"create sqlist success!"
template
int sqlist::getlength()
//獲取指定元素
template
bool sqlist::getelem(int i, t &e)
e = data[i-1];
return
true;
}//插入元素
template
bool sqlist::listinsert(int i, t e)
data[i-1] = e; //將待插入的元素賦值給插入位置
length++; //將順序表的長度增加乙個
return
true;
}//刪除元素
template
bool sqlist::listdelete(int i, t &e)
}length--; //將順序表的長度刪除乙個
return
true;
}template
void sqlist::display()
cout
int main();
sqlist->creatlist(arr, 5);
sqlist->display();
cout
<<"get element length is :"
sqlist->getelem(2, a);
cout
<<"get element is : "
sqlist->display();
int b;
sqlist->listdelete(2, b);
cout
<<"delete element is : "
delete sqlist;
return0;}
//棧中建立物件
int main01();
sqlist.creatlist(arr, 5);
sqlist.display();
cout
<<"get element length is :"
sqlist.getelem(2, a);
cout
<<"get element is : "
<2, 100);
sqlist.display();
int b;
sqlist.listdelete(2, b);
cout
<<"delete element is : "
return
0;}
ps: 順序表的三種**實現過程都寫完了,其中有學習到了一點新的知識!不錯!有問題歡迎指正哦 ^_^ C 模板實現順序表
pragma once include include include linearlist.h using namespace std const int defaultsize 100 templateclass seqlist public linearlist int size const ...
模板實現順序表
模板就是實現與型別無關的 增加了 的復用性。模板分為模板函式和模板類 模板函式的格式typedef 返回型別 函式名 引數列表 class也可以用typename,意義相同。當需要資料大於所給定的資料時這時我們會考慮增容。void vector checkcapacity void test 我們再...
模板實現順序表
一 seqlist.h pragma once include include include using namespace std template class seqlist seqlist void pushback const t x 最好傳引用,不傳引用,如果t為string,傳參時拷貝...