#include
using
namespace std;
template
<
typename t>
class
arraylist
output << endl;
return output;}}
;template
<
typename t>
inline arraylist
::arraylist()
template
<
typename t>
inline arraylist
::arraylist
(int capcity)
template
<
typename t>
inline arraylist::~
arraylist()
template
<
typename t>
inline
void arraylist
::inflate()
data = temp;
capcity *=2
;}//如果我的資料量小於當前容量的四分之一,那麼我就將容量縮一半;
//至於為什麼不是小於容量就縮。假設當前資料量為10 容量為20.那麼size小於10容量就會縮,但是此時如果資料量浮動了
//有多了乙個 那麼重新擴容要知道每次擴容都要遍歷複製一次 如此反覆非常浪費時間。所以小於四分之一才縮。
if(size <
0.25
* capcity)
data = temp;
capcity /=2
;}}template
<
typename t>
inline
void arraylist
::insert
(t e,
int index)
data[index]
= e;
size++;}
template
<
typename t>
void arraylist
::insertfirst
(t e)
template
<
typename t>
inline
void arraylist
::insert
(t e)
template
<
typename t>
void arraylist
::sortinsert
(t e)
}insert
(e,0);
}template
<
typename t>
inline t arraylist
::mydelete
(int index)
size--
;return val;
}template
<
typename t>
inline t arraylist
::mydeletelast()
template
<
typename t>
t arraylist
::mydeletefirst()
template
<
typename t>
inline
int arraylist
::get
(t e)
}return-1
;}template
<
typename t>
t arraylist
::getval
(int index)
template
<
typename t>
t arraylist
::getfirst()
template
<
typename t>
t arraylist
::getlast()
template
<
typename t>
inline
void arraylist
::modify
(int index, t e)
template
<
typename t>
inline
int arraylist
::getsize()
template
<
typename t>
inline
int arraylist
::getcapacity()
template
<
typename t>
t arraylist
::sum()
template
<
typename t>
t arraylist
::sum
(int l)
return data[l]
+sum
(l +1)
;}template
<
typename t>
inline
void arraylist
::unionset
(arraylist& l, arraylist& ans)
template
<
typename t>
void arraylist
::interset
(arraylist& l, arraylist& ans)
C 模板實現順序表
pragma once include include include linearlist.h using namespace std const int defaultsize 100 templateclass seqlist public linearlist int size const ...
C 模板類實現順序表
define crt secure no warnings include using namespace std include define length 10 typedef int datatype class vector 建構函式 有size個值為data的元素 vector size ...
順序表C 模板實現
include using namespace std const int maxsize 20 template class sqlist template sqlist sqlist template sqlist sqlist template void sqlist creatlist t ...