Skip to content

Commit 9ed62b9

Browse files
authored
Update README.md
1 parent 2840e12 commit 9ed62b9

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ exp(x); log(x); log10(x); // e to the x, log base e, log base 10
354354
pow(x, y); sqrt(x); // x to the y, square root
355355
ceil(x); floor(x); // Round up or down (as a double)
356356
fabs(x); fmod(x, y); // Absolute value, x mod y
357+
double res = double(expenditure[mid1] + expenditure[mid2])/2; //keep floating point
358+
5/2 = 2 // int division returns floor
357359
```
358360
359361
## `assert.h`, `cassert` (Debugging Aid)
@@ -411,6 +413,11 @@ getline(cin, s); // Read line ending in '\n'
411413
for (char const &c: s) {
412414
std::cout << c << ' ';
413415
}
416+
417+
vector<int> freq(26, 0);
418+
for(auto c: a){
419+
freq[c-'a']+=1;
420+
}
414421
```
415422
416423
## `vector` (Variable sized array/stack with built in memory allocation)
@@ -433,6 +440,11 @@ for (vector<int>::iterator p=a.begin(); p!=a.end(); ++p)
433440
vector<int> b(a.begin(), a.end()); // b is copy of a
434441
vector<T> c(n, x); // c[0]..c[n-1] init to x
435442
T d[10]; vector<T> e(d, d+10); // e is initialized from d
443+
assert(!v.empty());
444+
v.erase(v.begin());
445+
bool myfunction (int i,int j) { return (i<j); }
446+
sort(prices.begin(), prices.end(), myfunction);
447+
436448
```
437449

438450
## `deque` (Array stack queue)
@@ -444,7 +456,7 @@ T d[10]; vector<T> e(d, d+10); // e is initialized from d
444456
a.push_front(x); // Puts x at a[0], shifts elements toward back
445457
a.pop_front(); // Removes a[0], shifts toward front
446458
```
447-
459+
448460
## `utility` (pair)
449461

450462
```cpp
@@ -474,6 +486,13 @@ a["hello"] = 3; // Add or replace element a["hello"]
474486
for (auto& p:a)
475487
cout << p.first << p.second; // Prints hello, 3
476488
a.size(); // 1
489+
490+
//find
491+
std::unordered_map<std::string,double>::const_iterator got = mymap.find (input);
492+
if ( got == mymap.end() )
493+
std::cout << "not found";
494+
else
495+
std::cout << got->first << " is " << got->second;
477496
```
478497

479498
## `set` (store unique elements - usually implemented as binary search trees - avg. time complexity: O(log n))

0 commit comments

Comments
 (0)