Solved: 17 - Pointer Arithmetic
This commit is contained in:
@@ -2,8 +2,24 @@
|
||||
|
||||
namespace pointers {
|
||||
|
||||
auto pointer_distance(const int* begin, const int* end) -> std::size_t { (void)begin; (void)end; return 0; }
|
||||
auto find_pointer(const int* begin, const int* end, int target) -> const int* { (void)begin; (void)end; (void)target; return end; }
|
||||
void reverse_in_place(int* begin, int* end) { (void)begin; (void)end; }
|
||||
auto pointer_distance(const int* begin, const int* end) -> std::size_t {
|
||||
return end - begin;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user