• <bdo id='DDcL1'></bdo><ul id='DDcL1'></ul>
  • <legend id='DDcL1'><style id='DDcL1'><dir id='DDcL1'><q id='DDcL1'></q></dir></style></legend>

        <small id='DDcL1'></small><noframes id='DDcL1'>

      1. <i id='DDcL1'><tr id='DDcL1'><dt id='DDcL1'><q id='DDcL1'><span id='DDcL1'><b id='DDcL1'><form id='DDcL1'><ins id='DDcL1'></ins><ul id='DDcL1'></ul><sub id='DDcL1'></sub></form><legend id='DDcL1'></legend><bdo id='DDcL1'><pre id='DDcL1'><center id='DDcL1'></center></pre></bdo></b><th id='DDcL1'></th></span></q></dt></tr></i><div id='DDcL1'><tfoot id='DDcL1'></tfoot><dl id='DDcL1'><fieldset id='DDcL1'></fieldset></dl></div>

        <tfoot id='DDcL1'></tfoot>
      2. 在前面插入向量

        时间:2023-09-15

        • <bdo id='b5GH2'></bdo><ul id='b5GH2'></ul>

              <tfoot id='b5GH2'></tfoot>
              <legend id='b5GH2'><style id='b5GH2'><dir id='b5GH2'><q id='b5GH2'></q></dir></style></legend>
              <i id='b5GH2'><tr id='b5GH2'><dt id='b5GH2'><q id='b5GH2'><span id='b5GH2'><b id='b5GH2'><form id='b5GH2'><ins id='b5GH2'></ins><ul id='b5GH2'></ul><sub id='b5GH2'></sub></form><legend id='b5GH2'></legend><bdo id='b5GH2'><pre id='b5GH2'><center id='b5GH2'></center></pre></bdo></b><th id='b5GH2'></th></span></q></dt></tr></i><div id='b5GH2'><tfoot id='b5GH2'></tfoot><dl id='b5GH2'><fieldset id='b5GH2'></fieldset></dl></div>
                <tbody id='b5GH2'></tbody>

              <small id='b5GH2'></small><noframes id='b5GH2'>

                  本文介绍了在前面插入向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  iterator insert ( iterator position, const T& x );
                  

                  std::Vector类的插入操作符的函数声明.

                  Is the function declaration of the insert operator of the std::Vector class.

                  这个函数的返回类型是一个指向插入元素的迭代器.我的问题是,鉴于这种返回类型,最有效的方法是什么(这是我正在运行的更大程序的一部分,速度至关重要,所以我正在寻找计算效率的方法) 在开头插入.是下面的吗?

                  This function's return type is an iterator pointing to the inserted element. My question is, given this return type, what is the most efficient way (this is part of a larger program I am running where speed is of the essence, so I am looking for the most computationally efficient way) of inserting at the beginning. Is it the following?

                  //Code 1
                  vector<int> intvector;
                  vector<int>::iterator it;
                  it = myvector.begin();
                  for(int i = 1; i <= 100000; i++){
                      it = intvector.insert(it,i);
                  }
                  

                  或者,

                  //Code 2
                  vector<int> intvector;
                  for(int i = 1; i <= 100000; i++){
                      intvector.insert(intvector.begin(),i);
                  }
                  

                  本质上,在代码 2 中,是参数,

                  Essentially, in Code 2, is the parameter,

                  intvector.begin() 
                  

                  与在代码 1 中使用返回的迭代器相比,成本高"在计算上进行评估,或者两者都应该同样便宜/成本高?

                  "Costly" to evaluate computationally as compared to using the returned iterator in Code 1 or should both be equally cheap/costly?

                  推荐答案

                  获取插入点的效率一点也不重要 - 每次执行时不断地将现有数据洗牌的低效率会让它相形见绌插入.

                  The efficiency of obtaining the insertion point won't matter in the least - it will be dwarfed by the inefficiency of constantly shuffling the existing data up every time you do an insertion.

                  为此使用 std::deque,这就是它的设计目的.

                  Use std::deque for this, that's what it was designed for.

                  这篇关于在前面插入向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如果向量为空, std::vector::data() 应该返回什么? 下一篇:如何一次将多个整数传递给一个向量?

                  相关文章

                  最新文章

                • <i id='9cRCJ'><tr id='9cRCJ'><dt id='9cRCJ'><q id='9cRCJ'><span id='9cRCJ'><b id='9cRCJ'><form id='9cRCJ'><ins id='9cRCJ'></ins><ul id='9cRCJ'></ul><sub id='9cRCJ'></sub></form><legend id='9cRCJ'></legend><bdo id='9cRCJ'><pre id='9cRCJ'><center id='9cRCJ'></center></pre></bdo></b><th id='9cRCJ'></th></span></q></dt></tr></i><div id='9cRCJ'><tfoot id='9cRCJ'></tfoot><dl id='9cRCJ'><fieldset id='9cRCJ'></fieldset></dl></div>

                  <tfoot id='9cRCJ'></tfoot>
                    <bdo id='9cRCJ'></bdo><ul id='9cRCJ'></ul>

                  <small id='9cRCJ'></small><noframes id='9cRCJ'>

                  <legend id='9cRCJ'><style id='9cRCJ'><dir id='9cRCJ'><q id='9cRCJ'></q></dir></style></legend>