resize
语法:
1 |
void resize( size_type num, TYPE val ); |
resize()改变双向队列的大小为num,另加入的元素都被填充为val。
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 |
源代码 /** * @brief Resizes the %deque to the specified number of elements. * @param new_size Number of elements the %deque should contain. * @param x Data with which new elements should be populated. * * This function will %resize the %deque to the specified number of * elements. If the number is smaller than the %deque's current size the * %deque is truncated, otherwise the %deque is extended and new elements * are populated with given data. */ void resize(size_type __new_size, const value_type& __x) { const size_type __len = size(); if (__new_size < __len) erase(this->_M_impl._M_start + __new_size, this->_M_impl._M_finish); else insert(this->_M_impl._M_finish, __new_size - __len, __x); } /** * @brief Resizes the %deque to the specified number of elements. * @param new_size Number of elements the %deque should contain. * * This function will resize the %deque to the specified number of * elements. If the number is smaller than the %deque's current size the * %deque is truncated, otherwise the %deque is extended and new elements * are default-constructed. */ void resize(size_type new_size) { resize(new_size, value_type()); } |
测试代码
测试结果
0 0 0 0 0 0 0 0 0 0 100 100 100
0 0 0 0 0 0 0 0 0 0