-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector_insert.h
More file actions
26 lines (23 loc) · 1001 Bytes
/
Vector_insert.h
File metadata and controls
26 lines (23 loc) · 1001 Bytes
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
//
// Created by TGL on 2017/12/16.
//
/******************************************************************************************
* Geliang Tian, Gltian@bit.edu.cn
* Copyright (c) 2017.
*
* Data Structures in C++
* ISBN: 7-302-33064-6 & 7-302-33065-3 & 7-302-29652-2 & 7-302-26883-3
* Junhui DENG, deng@tsinghua.edu.cn
* Computer Science & Technology, Tsinghua University
* Copyright (c) 2006-2013. All rights reserved.
******************************************************************************************/
#ifndef INC_2_VECTOR_VECTOR_INSERT_H
#define INC_2_VECTOR_VECTOR_INSERT_H
template <typename T> //将e作为秩为r元素插入
Rank Vector<T>::insert ( Rank r, T const& e ) { //assert: 0 <= r <= size
expand(); //若有必要,扩容
for ( int i = _size; i > r; i-- ) _elem[i] = _elem[i-1]; //自后向前,后继元素顺次后移一个单元
_elem[r] = e; _size++; //置入新元素并更新容量
return r; //返回秩
}
#endif //INC_2_VECTOR_VECTOR_INSERT_H