Skip to content

Commit e06cced

Browse files
TylerMSFTTylerMSFT
authored andcommitted
fix another example
1 parent 48aab91 commit e06cced

1 file changed

Lines changed: 28 additions & 25 deletions

File tree

‎docs/standard-library/algorithm-functions.md‎

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ The source ranges aren't modified by `binary_search`.
326326

327327
The value types of the forward iterators must be less-than comparable to be ordered. That is, given two elements, you can determine either that one is less than the other, or that they're equivalent. (Here, equivalent means that neither is less than the other.) This comparison results in an ordering between the nonequivalent elements.
328328

329-
The complexity of the algorithm is logarithmic for random-access iterators and linear otherwise, with the number of steps proportional to (`last` - `first`).
329+
The complexity of the algorithm is logarithmic for random-access iterators and linear otherwise, with the number of steps proportional to (`last-first`).
330330

331331
### Example
332332

@@ -2382,7 +2382,7 @@ The function object is invoked for each element in the range and doesn't need to
23822382

23832383
The range referenced must be valid. All pointers must be dereferenceable and, within the sequence, the last position must be reachable from the first by incrementation.
23842384

2385-
The complexity is linear, with exactly `last` - `first` calls made to the generator.
2385+
The complexity is linear, with exactly `last - first` calls made to the generator.
23862386

23872387
### Example
23882388

@@ -6941,39 +6941,42 @@ The complexity is linear. It makes (`last` - `first`) comparisons for equality a
69416941

69426942
int main()
69436943
{
6944-
using namespace std;
6945-
vector<int> v1;
6946-
vector<int>::iterator Iter1;
6944+
std::vector<int> v;
69476945

6948-
int i;
6949-
for ( i = 0 ; i <= 9 ; i++ )
6950-
v1.push_back( i );
6946+
for (int i = 0; i < 10; i++)
6947+
{
6948+
v.push_back(i);
6949+
}
69516950

6952-
int ii;
6953-
for ( ii = 0 ; ii <= 3 ; ii++ )
6954-
v1.push_back( 7 );
6951+
for (int i = 0; i < 3; i++)
6952+
{
6953+
v.push_back(7);
6954+
}
69556955

6956-
random_shuffle (v1.begin( ), v1.end( ) );
6957-
cout << "The original vector v1 is:\n ( " ;
6958-
for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
6959-
cout << *Iter1 << " ";
6960-
cout << ")." << endl;
6956+
std::cout << "The original vector v is:\n ( ";
6957+
for (auto iter = v.begin(); iter != v.end(); iter++)
6958+
{
6959+
std::cout << *iter << " ";
6960+
}
6961+
std::cout << ")." << std::endl;
69616962

69626963
// Replace elements with a value of 7 with a value of 700
6963-
replace (v1.begin( ), v1.end( ), 7 , 700);
6964+
replace(v.begin(), v.end(), 7, 700);
69646965

6965-
cout << "The vector v1 with a value 700 replacing that of 7 is:\n ( " ;
6966-
for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
6967-
cout << *Iter1 << " ";
6968-
cout << ")." << endl;
6966+
std::cout << "The vector v with 7s replaced with 700s:\n ( ";
6967+
for (auto iter = v.begin(); iter != v.end(); iter++)
6968+
{
6969+
std::cout << *iter << " ";
6970+
}
6971+
std::cout << ")." << std::endl;
69696972
}
69706973
```
69716974

69726975
```Output
6973-
The original vector v1 is:
6974-
( 4 7 7 7 0 5 7 1 6 9 3 7 8 2 ).
6975-
The vector v1 with a value 700 replacing that of 7 is:
6976-
( 4 700 700 700 0 5 700 1 6 9 3 700 8 2 ).
6976+
The original vector v is:
6977+
( 0 1 2 3 4 5 6 7 8 9 7 7 7 ).
6978+
The vector v with 7s replaced with 700s:
6979+
( 0 1 2 3 4 5 6 700 8 9 700 700 700 ).
69776980
```
69786981

69796982
## <a name="replace_copy"></a> `replace_copy`

0 commit comments

Comments
 (0)