Data Structure trainer 01 linear Table Implementation

Source: Internet
Author: User

The knowledge points of C ++ are fragmented and tedious, but they do not have any effect in conclusion. More problems should be found in practice. Today, I wrote the implementation code for linear tables in "data structures, algorithms, and application C ++ language descriptions", and I feel a lot unfamiliar with the ability to write code.

During the compilation process, I found several issues that are worth noting:

1. My code is written through a class template. Many people put declarations and implementations in a header file when writing code. primer says that export can be used for separate compilation. I am not very familiar with this, but I got it by using two # ifndef .... # endif achieves the statement placed in. h. The implementation is placed in. cpp.

2. In the template class, you must add <> to the Declaration for <, or else the compilation fails.

3. cout refresh. For example, for fun (int & x), if we use cout <fun (y) <y; the screen does not display the updated value of y, instead, it calls the value before y. It is correct to divide it into two cout for output, or refresh the output.

Okay, paste the code: implement the environment vs2010

 MY_LINEARLIST_H<ostream> < T> cap = ~ find( pos, T& hold)  search( T& x) <T>& drop( pos, T&<T>& insert( pos,  T& printt(ostream& os)&  << (ostream& os,  LinearList<T>&*
 MY_LINEARLIST_CPP<cstdlib><ostream>< T><T>::LinearList(= == < T><T>::~LinearList( (element !=< T> LinearList<T> size == < T> LinearList<T>< T> LinearList<T>::find( pos,T& hold)  (pos > size || pos < )  = element[pos- < T> LinearList<T>::search( T& x)  ( i=; i<size; ++ (element[i] = i+ < T><T>& LinearList<T>::drop( pos, T& (pos > size || pos < = element[pos-( i=pos; i<size; ++-] =-- *< T><T>& LinearList<T>::insert( pos,  T&(size ==* newElement =  T[capacity*<<=  ( i=; i<pos; ++-] = element[i-=( i=pos; i<size; +++] =++=( i=size; i>=pos; --= element[i--] =++ *< T> LinearList<T>::printt(ostream& )  ( i=; i<size; ++ << element[i] <<  < T>& << (ostream& ,  LinearList<T>&);  
       LinearList<> L(       y=     L.insert (,         cout << L <<     L.insert (,         cout << L <<     L.insert (,         cout << L <<     cout <<  << y <<     cout <<  << L.find(,y) <<  << y <<     cout <<  << y <<  }

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.