Solved: 17 - Pointer Arithmetic
This commit is contained in:
@@ -2,8 +2,24 @@
|
|||||||
|
|
||||||
namespace pointers {
|
namespace pointers {
|
||||||
|
|
||||||
auto pointer_distance(const int* begin, const int* end) -> std::size_t { (void)begin; (void)end; return 0; }
|
auto pointer_distance(const int* begin, const int* end) -> std::size_t {
|
||||||
auto find_pointer(const int* begin, const int* end, int target) -> const int* { (void)begin; (void)end; (void)target; return end; }
|
return end - begin;
|
||||||
void reverse_in_place(int* begin, int* end) { (void)begin; (void)end; }
|
}
|
||||||
|
|
||||||
|
auto find_pointer(const int* begin, const int* end, int target) -> const int* {
|
||||||
|
while (*begin != target && ++begin != end) {
|
||||||
|
if (*begin == target) return begin;
|
||||||
|
begin++;
|
||||||
|
}
|
||||||
|
return begin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reverse_in_place(int* begin, int* end) {
|
||||||
|
while (begin != end && begin != --end) {
|
||||||
|
const auto aux = *begin;
|
||||||
|
*begin++ = *end;
|
||||||
|
*end = aux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace pointers
|
} // namespace pointers
|
||||||
|
|||||||
Reference in New Issue
Block a user