insert
语法:
1 2 |
iterator insert( iterator pos, size_type num, const TYPE &val ); void insert( iterator pos, input_iterator start, input_iterator end ); |
insert()在pos前插入num个val值,或者插入从start到end范围内的元素到pos前面。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
源代码 /** * @brief Inserts given value into %deque before specified iterator. * @param position An iterator into the %deque. * @param x Data to be inserted. * @return An iterator that points to the inserted data. * * This function will insert a copy of the given value before the * specified location. */ iterator insert(iterator position, const value_type& __x); /** * @brief Inserts a number of copies of given data into the %deque. * @param position An iterator into the %deque. * @param n Number of elements to be inserted. * @param x Data to be inserted. * * This function will insert a specified number of copies of the given * data before the location specified by @a position. */ void insert(iterator __position, size_type __n, const value_type& __x) { _M_fill_insert(__position, __n, __x); } /** * @brief Inserts a range into the %deque. * @param position An iterator into the %deque. * @param first An input iterator. * @param last An input iterator. * * This function will insert copies of the data in the range [first,last) * into the %deque before the location specified by @a pos. This is * known as "range insert." */ template<typename _InputIterator> void insert(iterator __position, _InputIterator __first, _InputIterator __last) { // Check whether it's an integral type. If so, it's not an iterator. typedef typename _Is_integer<_InputIterator>::_Integral _Integral; _M_insert_dispatch(__position, __first, __last, _Integral()); |
测试代码
测试结果
9 9 9 9 9 9 9 9 9 9
1 1 9 9 9 9 9 9 9 9 9 9
8 8 8 8 8 1 1 9 9 9 9 9 9 9 9 9 9
《双向队列insert 函数运用实例》上有1条评论
评论已关闭。