青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

我輩豈是蓬蒿人!

C++ && keyWordSpotting

  C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
  11 Posts :: 0 Stories :: 4 Comments :: 0 Trackbacks

常用鏈接

留言簿(9)

我參與的團隊

搜索

  •  

積分與排名

  • 積分 - 7323
  • 排名 - 1369

最新評論

閱讀排行榜

評論排行榜

Syntax:
														
1?#include?<vector>
2?void?assign(?size_type?num,?const?TYPE&?val?);
3?void?assign(?input_iterator?start,?input_iterator?end?);

The assign() function either gives the current vector the values from start to end, or gives it num copies of val.

This function will destroy the previous contents of the vector.

For example, the following code uses assign() to put 10 copies of the integer 42 into a vector:

 vector<int> v;
 v.assign( 10, 42 );
 for( int i = 0; i < v.size(); i++ ) {
   cout << v[i] << " ";
 }
 cout << endl;            

The above code displays the following output:

 42 42 42 42 42 42 42 42 42 42          

The next example shows how assign() can be used to copy one vector to another:

 vector<int> v1;
 for( int i = 0; i < 10; i++ ) {
   v1.push_back( i );
 }              

 vector<int> v2;
 v2.assign( v1.begin(), v1.end() );             

 for( int i = 0; i < v2.size(); i++ ) {
   cout << v2[i] << " ";
 }
 cout << endl;            

When run, the above code displays the following output:

 0 1 2 3 4 5 6 7 8 9

back
Syntax:
				
1?#include?<vector>
2?TYPE&?back();
3?const?TYPE&?back()?const;

The back() function returns a reference to the last element in the vector.

For example:

 vector<int> v;
 for( int i = 0; i < 5; i++ ) {
   v.push_back(i);
 }
 cout << "The first element is " << v.front()
      << " and the last element is " << v.back() << endl;           

This code produces the following output:

 The first element is 0 and the last element is 4               


at
Syntax:
  #include <vector>
  TYPE& at( size_type loc );
  const TYPE& at( size_type loc ) const;

The at() function returns a reference to the element in the vector at index loc. The at() function is safer than the [] operator, because it won't let you reference items outside the bounds of the vector.

For example, consider the following code:

 vector<int> v( 5, 1 );
 for( int i = 0; i < 10; i++ ) {
   cout << "Element " << i << " is " << v[i] << endl;
 }              

This code overrunns the end of the vector, producing potentially dangerous results. The following code would be much safer:

 vector<int> v( 5, 1 );
 for( int i = 0; i < 10; i++ ) {
   cout << "Element " << i << " is " << v.at(i) << endl;
 }              

Instead of attempting to read garbage values from memory, the at() function will realize that it is about to overrun the vector and will throw an exception.

capacity
Syntax:
  #include <vector>
  size_type capacity() const;

The capacity() function returns the number of elements that the vector can hold before it will need to allocate more space.

For example, the following code uses two different methods to set the capacity of two vectors. One method passes an argument to the constructor that suggests an initial size, the other method calls the reserve function to achieve a similar goal:

 vector<int> v1(10);
 cout << "The capacity of v1 is " << v1.capacity() << endl;
 vector<int> v2;
 v2.reserve(20);
 cout << "The capacity of v2 is " << v2.capacity() << endl;         

When run, the above code produces the following output:

 The capacity of v1 is 10
 The capacity of v2 is 20               

C++ containers are designed to grow in size dynamically. This frees the programmer from having to worry about storing an arbitrary number of elements in a container. However, sometimes the programmer can improve the performance of her program by giving hints to the compiler about the size of the containers that the program will use. These hints come in the form of the reserve() function and the constructor used in the above example, which tell the compiler how large the container is expected to get.

The capacity() function runs in constant time.


begin
Syntax:
  #include <vector>
  iterator begin();
  const_iterator begin() const;

The function begin() returns an iterator to the first element of the vector. begin() should run in constant time.

For example, the following code uses begin() to initialize an iterator that is used to traverse a list:

   // Create a list of characters
   list<char> charList;
   for( int i=0; i < 10; i++ ) {
     charList.push_front( i + 65 );
   }
   // Display the list
   list<char>::iterator theIterator;
   for( theIterator = charList.begin(); theIterator != charList.end(); theIterator++ ) {
     cout << *theIterator;
   }            
max_size
Syntax:
  #include <vector>
  size_type max_size() const;

The max_size() function returns the maximum number of elements that the vector can hold. The max_size() function should not be confused with the size() or capacity() functions, which return the number of elements currently in the vector and the the number of elements that the vector will be able to hold before more memory will have to be allocated, respectively.

clear
Syntax:
  #include <vector>
  void clear();

The function clear() deletes all of the elements in the vector. clear() runs in linear time.

empty
Syntax:
  #include <vector>
  bool empty() const;

The empty() function returns true if the vector has no elements, false otherwise.

For example, the following code uses empty() as the stopping condition on a (C/C++ Keywords) while loop to clear a vector and display its contents in reverse order:

 vector<int> v;
 for( int i = 0; i < 5; i++ ) {
   v.push_back(i);
 }
 while( !v.empty() ) {
   cout << v.back() << endl;
   v.pop_back();
 }              
end
Syntax:
  #include <vector>
  iterator end();
  const_iterator end() const;

The end() function returns an iterator just past the end of the vector.

Note that before you can access the last element of the vector using an iterator that you get from a call to end(), you'll have to decrement the iterator first. This is because end() doesn't point to the end of the vector; it points just past the end of the vector.

For example, in the following code, the first "cout" statement will display garbage, whereas the second statement will actually display the last element of the vector:

  vector<int> v1;
  v1.push_back( 0 );
  v1.push_back( 1 );
  v1.push_back( 2 );
  v1.push_back( 3 );

  int bad_val = *(v1.end());
  cout << "bad_val is " << bad_val << endl;

  int good_val = *(v1.end() - 1);
  cout << "good_val is " << good_val << endl;

The next example shows how begin() and end() can be used to iterate through all of the members of a vector:

 vector<int> v1( 5, 789
  ); vector<int>::iterator it; for( it = v1.begin(); it !=
  v1.end(); it++ ) { cout << *it << endl; } 

The iterator is initialized with a call to begin(). After the body of the loop has been executed, the iterator is incremented and tested to see if it is equal to the result of calling end(). Since end() returns an iterator pointing to an element just after the last element of the vector, the loop will only stop once all of the elements of the vector have been displayed.

end() runs in constant time.


erase
Syntax:
  #include <vector>
  iterator erase( iterator loc );
  iterator erase( iterator start, iterator end );

The erase() function either deletes the element at location loc, or deletes the elements between start and end (including start but not including end). The return value is the element after the last element erased.

The first version of erase (the version that deletes a single element at location loc) runs in constant time for lists and linear time for vectors, dequeues, and strings. The multiple-element version of erase always takes linear time.

For example:

 // Create a vector, load it with the first ten characters of the alphabet
 vector<char> alphaVector;
 for( int i=0; i < 10; i++ ) {
   alphaVector.push_back( i + 65 );
 }
 int size = alphaVector.size();
 vector<char>::iterator startIterator;
 vector<char>::iterator tempIterator;
 for( int i=0; i < size; i++ ) {
   startIterator = alphaVector.begin();
   alphaVector.erase( startIterator );
   // Display the vector
   for( tempIterator = alphaVector.begin(); tempIterator != alphaVector.end(); tempIterator++ ) {
     cout << *tempIterator;
   }
   cout << endl;
 }              

That code would display the following output:

 BCDEFGHIJ
 CDEFGHIJ
 DEFGHIJ
 EFGHIJ
 FGHIJ
 GHIJ
 HIJ
 IJ
 J              

In the next example, erase() is called with two iterators to delete a range of elements from a vector:

 // create a vector, load it with the first ten characters of the alphabet
 vector<char> alphaVector;
 for( int i=0; i < 10; i++ ) {
   alphaVector.push_back( i + 65 );
 }
 // display the complete vector
 for( int i = 0; i < alphaVector.size(); i++ ) {
   cout << alphaVector[i];
 }
 cout << endl;            

 // use erase to remove all but the first two and last three elements
 // of the vector
 alphaVector.erase( alphaVector.begin()+2, alphaVector.end()-3 );
 // display the modified vector
 for( int i = 0; i < alphaVector.size(); i++ ) {
   cout << alphaVector[i];
 }
 cout << endl;            

When run, the above code displays:

 ABCDEFGHIJ
 ABHIJ          

front
Syntax:
  #include <vector>
  TYPE& front();
  const TYPE& front() const;

The front() function returns a reference to the first element of the vector, and runs in constant time.


insert
Syntax:
  #include <vector>
  iterator insert( iterator loc, const TYPE& val );
  void insert( iterator loc, size_type num, const TYPE& val );
  template<TYPE> void insert( iterator loc, input_iterator start, input_iterator end );

The insert() function either:

  • inserts val before loc, returning an iterator to the element inserted,
  • inserts num copies of val before loc, or
  • inserts the elements from start to end before loc.

Note that inserting elements into a vector can be relatively time-intensive, since the underlying data structure for a vector is an array. In order to insert data into an array, you might need to displace a lot of the elements of that array, and this can take linear time. If you are planning on doing a lot of insertions into your vector and you care about speed, you might be better off using a container that has a linked list as its underlying data structure (such as a List or a Deque).

For example, the following code uses the insert() function to splice four copies of the character 'C' into a vector of characters:

 // Create a vector, load it with the first 10 characters of the alphabet
 vector<char> alphaVector;
 for( int i=0; i < 10; i++ ) {
   alphaVector.push_back( i + 65 );
 }              

 // Insert four C's into the vector
 vector<char>::iterator theIterator = alphaVector.begin();
 alphaVector.insert( theIterator, 4, 'C' );             

 // Display the vector
 for( theIterator = alphaVector.begin(); theIterator != alphaVector.end(); theIterator++ )    {
   cout << *theIterator;
 }              

This code would display:

 CCCCABCDEFGHIJ         

Here is another example of the insert() function. In this code, insert() is used to append the contents of one vector onto the end of another:

  vector<int> v1;
  v1.push_back( 0 );
  v1.push_back( 1 );
  v1.push_back( 2 );
  v1.push_back( 3 );

  vector<int> v2;
  v2.push_back( 5 );
  v2.push_back( 6 );
  v2.push_back( 7 );
  v2.push_back( 8 );

  cout << "Before, v2 is: ";
  for( int i = 0; i < v2.size(); i++ ) {
    cout << v2[i] << " ";
  }
  cout << endl;

  v2.insert( v2.end(), v1.begin(), v1.end() );

  cout << "After, v2 is: ";
  for( int i = 0; i < v2.size(); i++ ) {
    cout << v2[i] << " ";
  }
  cout << endl;

When run, this code displays:

  Before, v2 is: 5 6 7 8
  After, v2 is: 5 6 7 8 0 1 2 3

Vector constructors
Syntax:
  #include <vector>
  vector();
  vector( const vector& c );
  vector( size_type num, const TYPE& val = TYPE() );
  vector( input_iterator start, input_iterator end );
  ~vector();

The default vector constructor takes no arguments, creates a new instance of that vector.

The second constructor is a default copy constructor that can be used to create a new vector that is a copy of the given vector c.

The third constructor creates a vector with space for num objects. If val is specified, each of those objects will be given that value. For example, the following code creates a vector consisting of five copies of the integer 42:

 vector<int> v1( 5, 42 );         

The last constructor creates a vector that is initialized to contain the elements between start and end. For example:

 // create a vector of random integers
 cout << "original vector: ";
 vector<int> v;
 for( int i = 0; i < 10; i++ ) {
   int num = (int) rand() % 10;
   cout << num << " ";
   v.push_back( num );
 }
 cout << endl;            

 // find the first element of v that is even
 vector<int>::iterator iter1 = v.begin();
 while( iter1 != v.end() && *iter1 % 2 != 0 ) {
   iter1++;
 }              

 // find the last element of v that is even
 vector<int>::iterator iter2 = v.end();
 do {
   iter2--;
 } while( iter2 != v.begin() && *iter2 % 2 != 0 );              

 cout << "first even number: " << *iter1 << ", last even number: " << *iter2 << endl;         

 cout << "new vector: ";
 vector<int> v2( iter1, iter2 );
 for( int i = 0; i < v2.size(); i++ ) {
   cout << v2[i] << " ";
 }
 cout << endl;            

When run, this code displays the following output:

 original vector: 1 9 7 9 2 7 2 1 9 8
 first even number: 2, last even number: 8
 new vector: 2 7 2 1 9          

All of these constructors run in linear time except the first, which runs in constant time.

The default destructor is called when the vector should be destroyed.


pop_back
Syntax:
  #include <vector>
  void pop_back();

The pop_back() function removes the last element of the vector.

pop_back() runs in constant time.


push_back
Syntax:
  #include <vector>
  void push_back( const TYPE& val );

The push_back() function appends val to the end of the vector.

For example, the following code puts 10 integers into a list:

   list<int> the_list;
   for( int i = 0; i < 10; i++ )
     the_list.push_back( i );           

When displayed, the resulting list would look like this:

 0 1 2 3 4 5 6 7 8 9            

push_back() runs in constant time.


rbegin
Syntax:
  #include <vector>
  reverse_iterator rbegin();
  const_reverse_iterator rbegin() const;

The rbegin() function returns a reverse_iterator to the end of the current vector.

rbegin() runs in constant time.


rend
Syntax:
  #include <vector>
  reverse_iterator rend();
  const_reverse_iterator rend() const;

The function rend() returns a reverse_iterator to the beginning of the current vector.

rend() runs in constant time.


reserve
Syntax:
  #include <vector>
  void reserve( size_type size );

The reserve() function sets the capacity of the vector to at least size.

reserve() runs in linear time.


resize
Syntax:
  #include <vector>
  void resize( size_type num, const TYPE& val = TYPE() );

The function resize() changes the size of the vector to size. If val is specified then any newly-created elements will be initialized to have a value of val.

This function runs in linear time.


size
Syntax:
  #include <vector>
  size_type size() const;

The size() function returns the number of elements in the current vector.


swap
Syntax:
  #include <vector>
  void swap( const container& from );

The swap() function exchanges the elements of the current vector with those of from. This function operates in constant time.

For example, the following code uses the swap() function to exchange the values of two strings:

   string first( "This comes first" );
   string second( "And this is second" );
   first.swap( second );
   cout << first << endl;
   cout << second << endl;          

The above code displays:

   And this is second
   This comes first             

Vector operators
Syntax:
  #include <vector>
  TYPE& operator[]( size_type index );
  const TYPE& operator[]( size_type index ) const;
  vector operator=(const vector& c2);
  bool operator==(const vector& c1, const vector& c2);
  bool operator!=(const vector& c1, const vector& c2);
  bool operator<(const vector& c1, const vector& c2);
  bool operator>(const vector& c1, const vector& c2);
  bool operator<=(const vector& c1, const vector& c2);
  bool operator>=(const vector& c1, const vector& c2);

All of the C++ containers can be compared and assigned with the standard comparison operators: ==, !=, <=, >=, <, >, and =. Individual elements of a vector can be examined with the [] operator.

Performing a comparison or assigning one vector to another takes linear time. The [] operator runs in constant time.

Two vectors are equal if:

  1. Their size is the same, and
  2. Each member in location i in one vector is equal to the the member in location i in the other vector.

Comparisons among vectors are done lexicographically.

For example, the following code uses the [] operator to access all of the elements of a vector:

 vector<int> v( 5, 1 );
 for( int i = 0; i < v.size(); i++ ) {
   cout << "Element " << i << " is " << v[i] << endl;
 }              

posted on 2006-08-13 19:52 keyws 閱讀(687) 評論(0)  編輯 收藏 引用 所屬分類: STL

只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            午夜一级在线看亚洲| 国产亚洲午夜| 亚洲欧美视频一区二区三区| 亚洲人成网站色ww在线| 免费高清在线一区| 美女国内精品自产拍在线播放| 久久一区欧美| 亚洲一区二区三区在线看| 日韩亚洲在线| 亚洲精品久久久久久下一站| 亚洲国产毛片完整版| 日韩视频一区二区| 国产精品久久久久久影院8一贰佰 国产精品久久久久久影视 | 亚洲欧美资源在线| 午夜天堂精品久久久久| 久久只有精品| 日韩视频亚洲视频| 欧美一区2区视频在线观看| 久久三级福利| 欧美色图五月天| 国产一区久久| 亚洲破处大片| 久久超碰97人人做人人爱| 免播放器亚洲| 亚洲一二三四久久| 美女图片一区二区| 国产精品久久久久影院色老大| 一本色道久久综合亚洲二区三区| 一区二区毛片| 先锋影音网一区二区| 蜜臀a∨国产成人精品| 99riav久久精品riav| 久久久久国产一区二区三区| 欧美屁股在线| 亚洲国产成人久久综合一区| 亚洲在线一区二区| 欧美激情精品| 久久精品国产免费看久久精品| 日韩网站在线| 久久久久久电影| 国产精品毛片a∨一区二区三区|国| 久久精品免视看| 欧美视频在线观看免费| 亚洲国产成人精品女人久久久 | 亚洲美女网站| 久久理论片午夜琪琪电影网| 欧美日本国产在线| 亚洲成色777777在线观看影院| 国产三级欧美三级| 亚洲精品中文字幕在线| 久久香蕉国产线看观看网| 一区二区三区国产精品| 欧美精品一区视频| 久久久www成人免费毛片麻豆| 国产一区欧美| 中文av字幕一区| 亚洲福利视频一区二区| 久久精品72免费观看| 国产美女一区二区| 香蕉免费一区二区三区在线观看| 亚洲一区日本| 日韩视频在线观看一区二区| 欧美不卡激情三级在线观看| 国产在线拍偷自揄拍精品| 久久国产精品99国产| 在线一区二区三区四区五区| 欧美精品一区二区三区蜜桃| 日韩午夜电影| 亚洲人成在线播放| 欧美精品一线| 亚洲一区在线免费| 亚洲综合首页| 国产一区二区中文字幕免费看| 亚洲激情在线激情| 看欧美日韩国产| 久久偷窥视频| 亚洲精品在线观看视频| 一本到12不卡视频在线dvd| 国产精品xxxxx| 久久久99久久精品女同性| 欧美专区在线观看一区| 一区二区三区无毛| 亚洲激情精品| 国产精品青草久久久久福利99| 好吊色欧美一区二区三区视频| 亚洲国产精品久久精品怡红院| 亚洲乱码国产乱码精品精98午夜| 亚洲午夜精品| 午夜精品影院在线观看| 亚洲国产欧美精品| 亚洲午夜精品福利| 国产综合久久| 99国产精品一区| 精品成人久久| 99亚洲视频| 一区二区自拍| 亚洲视频电影图片偷拍一区| 国产亚洲a∨片在线观看| 欧美韩日视频| 国产精品女人毛片| 免费久久久一本精品久久区| 欧美日本精品| 久久综合给合久久狠狠色| 欧美日韩亚洲国产一区| 久久亚洲综合网| 欧美三级网址| 欧美激情影音先锋| 国产日韩精品视频一区二区三区 | 国产人成精品一区二区三| 久久久久久久网| 欧美日韩人人澡狠狠躁视频| 久久综合久久综合久久| 欧美性做爰毛片| 国产精品久久久一区麻豆最新章节| 欧美日韩精品欧美日韩精品一 | 在线观看视频一区二区| 亚洲国产专区| 国产视频亚洲精品| 在线视频日韩| 99riav久久精品riav| 久久久久久久一区二区三区| 亚洲一区二区视频在线| 欧美1区2区| 免费观看成人鲁鲁鲁鲁鲁视频| 欧美在线视频免费观看| 亚洲一区在线看| 欧美激情网友自拍| 欧美二区在线看| 亚洲国产第一页| 另类春色校园亚洲| 欧美电影资源| 亚洲激情综合| 欧美国产精品劲爆| 亚洲国产精品一区二区www在线| 欧美激情第二页| 亚洲第一综合天堂另类专| 亚洲欧洲日本国产| 欧美日本高清| 夜夜狂射影院欧美极品| 艳女tv在线观看国产一区| 欧美日本精品在线| 一区二区三区国产精华| 亚洲私人影吧| 国产精品久久久久国产精品日日| 欧美尤物巨大精品爽| 国产精品视频精品视频| 亚洲午夜伦理| 久久久久这里只有精品| 国产亚洲在线| 久久久噜久噜久久综合| 久久中文字幕一区| 亚洲国产精品第一区二区| 免费试看一区| 欧美成人亚洲| 亚洲永久免费| 国产精品一卡二卡| 亚洲欧美福利一区二区| 免费成人av资源网| 亚洲大胆女人| 欧美jizz19性欧美| 欧美中文在线视频| 亚洲二区在线观看| 欧美成人精品一区二区| 亚洲国产片色| 在线电影国产精品| 欧美激情一区二区三区| 日韩系列在线| 午夜精品视频| 狠狠色综合色综合网络| 亚洲一区二区三区国产| 久久国产精品72免费观看| 好看的日韩视频| 久热精品视频在线观看一区| 99国产精品久久| 欧美影院一区| 一区二区自拍| 亚洲女ⅴideoshd黑人| 欧美国产成人精品| 亚洲视频一区| 国产一区二区高清视频| 亚洲素人在线| 亚洲风情亚aⅴ在线发布| 久久9热精品视频| 亚洲影视在线| 亚洲韩国日本中文字幕| 欧美理论在线| 亚洲中字在线| 欧美成人精品在线播放| 午夜精彩国产免费不卡不顿大片| 性欧美video另类hd性玩具| 久久久久99精品国产片| 亚洲国产精品一区二区www在线| 久久久综合免费视频| 亚久久调教视频| 欧美激情视频在线播放| 亚洲一区视频| 亚洲欧洲精品一区二区精品久久久| 欧美亚洲一区二区在线观看| 美国十次成人| 一区二区欧美国产|