-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtils.cpp
More file actions
82 lines (66 loc) · 1.53 KB
/
Utils.cpp
File metadata and controls
82 lines (66 loc) · 1.53 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// Created by 赵健 on 2021/8/15.
//
#include <iostream>
#include "Utils.h"
void Utils::printVector(vector<int> obj) {
vector<int>::iterator it;
for (it = obj.begin(); it != obj.end(); it++) {
cout << *it << " ";
}
}
void Utils::printVector2(vector<vector<int>> obj) {
vector<vector<int>>::iterator it;
for (it = obj.begin(); it != obj.end(); it++) {
printVector(*it);
}
}
vector<int> Utils::vector001() {
vector<int> obj;
int nums[] = {2, 7, 11, 15};
obj.reserve(getLen(nums));
for (int i = 0; i < getLen(nums); ++i) {
obj.push_back(nums[i]);
}
return obj;
}
int Utils::getLen(int *ar) {
int cnt = sizeof(*ar) / sizeof(ar[0]);
return cnt;
}
vector<int> Utils::vectorFrom(int *arr) {
int len = getLen(arr);
vector<int> obj(len);
for (int i = 0; i < len; ++i) {
obj.push_back(arr[i]);
}
return obj;
}
void Utils::printVectorWithAddr(vector<int> obj) {
// vector<int>::iterator it;
// for (it = obj.begin(); it != obj.end(); it++) {
//
// }
}
void Utils::output(const string &s) {
std::cout << s << " ";
}
void Utils::outint(int num) {
std::cout << num << " ";
}
void Utils::printList(list<int> l) {
for_each(l.begin(), l.end(), outint);
}
void Utils::println(const string &s) {
cout << endl << s;
}
void Utils::ShowDouble(double v) {
std::cout.width(6);
std::cout << v << ' ';
}
void Utils::ShowInt(int num) {
std::cout << num << " ";
}
void Utils::display(const string &s) {
cout << s << " ";
}