Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pezy/Cpp-Primer
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Apr 24, 2015
2 parents 5fc880c + 416e11c commit b030bd6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ch09/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void insert(forward_list<string> &flst, string find, string insrt)
vec.resize(100) do? What if we next wrote vec.resize(10)?

```cpp
vec.resize(100); // adds 75 elements of value 0 to the back of vec
vec.resize(100); // adds 75 items to the back of vec. These added items are value initialized.
vec.resize(10); // erases 90 elements from the back of vec
```

Expand Down
3 changes: 2 additions & 1 deletion ch09/ex9_33.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// @Brief In the final example in this section what would happen
// if we did not assign the result of insert to begin?
// Write a program that omits this assignment to see if your expectation was correct.
// @Answer crash, cause the iterator is invalid after insert.
// @Answer crash, cause the iterator is invalid after insert. Because Iterators, pointers, and references to a
// vector or string are invalid if the container was reallocated.

#include <iostream>
#include <vector>
Expand Down
21 changes: 11 additions & 10 deletions ch09/ex9_52.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//
// ex9_52.cpp
// Exercise 9.52
// Exercise 9.52
//
// Created by pezy on 12/5/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
// @Brief Use a stack to process parenthesized expressions.
// When you see an open parenthesis, note that it was seen.
// When you see a close parenthesis after an open parenthesis,
// pop elements down to and including the open parenthesis off the stack.
// push a value onto the stack to indicate that a parenthesized expression was replaced.
// @Brief Use a stack to process parenthesized expressions.
// When you see an open parenthesis, note that it was seen.
// When you see a close parenthesis after an open parenthesis,
// pop elements down to and including the open parenthesis off the stack.
// push a value onto the stack to indicate that a parenthesized expression was replaced.

#include <stack>
using std::stack;
Expand All @@ -22,12 +22,13 @@ using std::cout; using std::endl;

int main()
{
string expr = "This is (Mooophy(awesome)((((wooooooooo))))) and (ocxs) over";
char repl = '#';
auto & expr = "This is (Mooophy(awesome)((((wooooooooo))))) and (ocxs) over";
auto repl = '#';
auto seen = 0;

stack<char> stk;
int seen = 0;

for ( auto c : expr ) {
for (auto c : expr) {
stk.push(c);
if ( c == '(' ) ++seen; // open
if ( seen && c == ')' ) { // pop elements down to the stack
Expand Down
3 changes: 3 additions & 0 deletions ch10/ex10_07.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ int main()
// the destination is large enough to hold the number of elements being written.
copy(lst.cbegin(), lst.cend(), vec.begin());

//another way to fix bug
//copy(lst.cbegin(), lst.cend(), back_inserter(vec));

// (b)
vector<int> v;
v.reserve(10);
Expand Down

0 comments on commit b030bd6

Please sign in to comment.