Skip to content

Commit

Permalink
fix exercise 16.3 16.4
Browse files Browse the repository at this point in the history
Add a test for exercise 16.3.
A better solution for exercise 16.4.
  • Loading branch information
Queequeg92 committed Nov 17, 2014
1 parent 234d594 commit 18b9548
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 11 additions & 0 deletions ch16/ex16.1.2.3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
//!

#include <iostream>
using std::cout;
using std::endl;

#include<vector>
using std::vector;

class Sales_data
{
Expand All @@ -41,6 +46,12 @@ int compare(const T& lhs, const T& rhs)

int main()
{
//! Test compare function
cout << compare(1, 0) << endl;

vector<int> vec1{1, 2, 3}, vec2{4, 5, 6};
cout << compare(vec1, vec2) << endl;

return 0;
}

10 changes: 3 additions & 7 deletions ch16/ex16.4/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@
template<typename iteratorT, typename valueT>
iteratorT find(const iteratorT& first, const iteratorT& last,const valueT& value )
{
if (first == last) return last;
else
{
for (auto it = first; it != last; ++it)
if(*it == value) return it;
return last;
}
auto iter = first;
while(iter != last && *iter != value) ++iter;
return iter;
}

int main()
Expand Down

0 comments on commit 18b9548

Please sign in to comment.