-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector_disordered.h
More file actions
25 lines (22 loc) · 964 Bytes
/
Vector_disordered.h
File metadata and controls
25 lines (22 loc) · 964 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
//
// 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_DISORDERED_H
#define INC_2_VECTOR_VECTOR_DISORDERED_H
template <typename T> int Vector<T>::disordered() const { //返回向量中逆序相邻元素对的总数
int n = 0; //计数器
for ( int i = 1; i < _size; i++ ) //逐一检查_size - 1对相邻元素
if ( _elem[i - 1] > _elem[i] ) n++; //逆序则计数
return n; //向量有序当且仅当n = 0
}
#endif //INC_2_VECTOR_VECTOR_DISORDERED_H