Introduction and use of C + + STL in ACM

Source: Internet
Author: User

The STL is all called the Standard Template Library, which is basically a template, it relies on templates, not objects, so you need to instantiate this template and choose the type you want to use.

The template is a kind of thing, you can look at this TOJ5250

Test instructions is for me to implement an array of arbitrary content that can be placed in a variable length.

My implementation code

#include <iostream>#include<malloc.h>using namespacestd;template<typename t>classvector{PrivateTp; intsize; intN;  Public: Vector () {p= (t*)malloc(Ten*sizeof(T)); Size=Ten; N=0;} voidPush_back (ConstT a) {    if(n==size) {p= (t*)realloc(P,Ten*sizeof(T)); size+=Ten;} * (p+n) =A; N++; } typedef T*Iterator; T*Begin () {returnp;} T*End () {returnp+n;}};intVector, deque, list, forward_list, array,string;//prohibit the use of vectors, lists, etc.intMain () {Vector<int>A;  for(intI=1; i<=5; i++) A.push_back (i); Vector<int>:: Iterator it;  for(It=a.begin (); It!=a.end (); + +it) {cout<<*it<<Endl; }}

Inside I used some kind of things, for the moment skip.

void push_back (const T a) {    if (n==size) {p= (t*) realloc (p,10*sizeof (T)); size+=10;}    * (p+n) =A;    n++;    }   
Well, look at this part.

Introduction and use of C + + STL in ACM

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.