FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-lib/src/sort.cpp at master · dst/cpp-lib · GitHub
dst
cpp-lib
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp-lib
/
src
/
sort.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (30 loc) · 799 Bytes
Breadcrumbs
cpp-lib
/
src
/
sort.cpp
Copy path
File metadata and controls
38 lines (30 loc) · 799 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* sortlib.cpp
*
* Created on: Nov 2, 2013
* Author: dst
*/
#
include
<
algorithm
>
using
std::vector;
//
sorting objects
class
obj
{};
inline
bool
comp
(
const
obj& a,
const
obj& b) {
//
returns bool!
//
compare objects, return true if a should be before b, false otherwise
return
true
;
/*
Example (sort by name, then by age)
* if (a.name.compare(b.name) == 0) {
* return a.age < b.age;
* } else {
* return a.name.compare(b.name) < 0; // string::compare returns -1, 0 or 1
* }
*/
}
inline
void
sortObjs
(vector<obj>& objs) {
sort
(objs.
begin
(), objs.
end
(), comp);
}
//
Sort array in descending order with reverse iterators
inline
void
reverseSort
(vector<
int
>& v) {
sort
(v.
rbegin
(), v.
rend
());
}
inline
void
sort
() {
}
Back
|
FazBrowse Home
|
New Git URL