Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- struct result{
- int nums[2];
- };
- result* xseek(int* a, int len, int x)
- {
- auto res = new result;
- int* b = a + --len;
- do {
- if((*a + *b) == x) {
- res->nums[0] = *a;
- res->nums[1] = *b;
- return res;
- } else if((*a + *b) < x) {
- a++;
- } else if((*a + *b) > x) {
- b--;
- }
- } while (a != b);
- }
- int main()
- {
- int arr[5] = {0, 1, 2, 3, 4};
- int* a = arr;
- auto res = xseek(a, 5, 7);
- std::cout << res->nums[0] << ',' << res->nums[1] << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement