-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortprocs.cpp
More file actions
29 lines (26 loc) · 1.07 KB
/
Copy pathsortprocs.cpp
File metadata and controls
29 lines (26 loc) · 1.07 KB
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
#include "../header/getprocs.h"
#include "../header/sortprocs.h"
#include <vector>
#include <algorithm>
using namespace std;
void SortProcs(vector<ProcInfo> &procs, KeyList k, bool asc) {
auto cmp = [&](const ProcInfo& a, const ProcInfo& b) {
switch (k) {
case NAME:
return asc ? a.szExeFile < b.szExeFile : a.szExeFile > b.szExeFile;
case ID:
return asc ? a.th32ProcessID < b.th32ProcessID : a.th32ProcessID > b.th32ProcessID;
case THREADS:
return asc ? a.cntThreads < b.cntThreads : a.cntThreads > b.cntThreads;
case DWSIZE:
return asc ? a.dwSize < b.dwSize : a.dwSize > b.dwSize;
case PRIORITY:
return asc ? a.pcPriClassBase < b.pcPriClassBase : a.pcPriClassBase > b.pcPriClassBase;
case PARENTID:
return asc ? a.th32ParentProcessID < b.th32ParentProcessID : a.th32ParentProcessID > b.th32ParentProcessID;
}
return false;
};
std::sort(procs.begin(), procs.end(), cmp);
return;
}