C++primer behind the advanced features can not look down, re-find a data structure of the book to see, Refueling!! The book is called "Data structure algorithm and C + + language description"!
Basic complete Insert, find, delete, print, oh, yes, that operator<< overload feeling indefinitely!!!
The reference code is as follows:
#include <iostream>//using namespace Std;template<class t>class linearlist{public:linearlist (int maxlistsize = 0); ~linearlist () {}bool IsEmpty () {return bool (length);}; int Length () {return Length;}; BOOL Find (int k,t& x); int Search (const t& a) const; linearlist<t>& Delete (int k,t &x); linearlist<t>& Insert (int k,t& x); void OutPut (Std::ostream &out) Const;private:int Length;int MaxSize; T *element;}; Template<class t>linearlist<t>::linearlist (int maxls) {MaxSize = Maxls;length = 0;element = new T[MaxLS];} Template<class t>bool linearlist<t>::find (int k, T &x) {if (k>maxsize| | k<0) Return false;x = Element[k-1];return true;} Template<class t>int linearlist<t>::search (const T &a) const{for (int i = 0;i < MaxSize; ++i) {if ( Element[i] = = a) return i++;} return 0;} Template<class t>linearlist<t>& linearlist<t>::D elete (int k,t &x) {if (This->find (k,x)) {for (int i = k-1;i<maxsize;i++){Element[i-1] = element[i];} length = Length-1;std::cout<<length<<std::endl;return *this;}} Template<class t>linearlist<t>& linearlist<t>::insert (int k,t &x) {if (length = = MaxSize) { std::cout<< "full! "<<std::endl;} for (int i = maxsize;i > k-1;i--) {element[i] = element[i-1];} Element[k] = X;length++;return *this;} Template<class t>void linearlist<t>::output (std::ostream &out) const{for (int i = 0;i < length;i++) out<<element[i]<< "";} Template<class t>std::ostream& operator<< (std::ostream& out,const LinearList<T>& a) {a . OutPut (out); return out;} int main () {int ftest = 0; Linearlist<int> ll (5); for (int i = 0; i< 5; ++i) {int temp = i * i;ll. Insert (i,temp);} Std::cout<<ll. Length () <<std::endl;std::cout<<ll<<std::endl;ll. Find (2,ftest); Std::cout<<ftest<<std::endl;ll. Delete (2,ftest); Std::cout<<ll. Length () <<std::endl;std::cout<<ll< <std::endl;return 0;}
Data structure 1---linear table