I will give you a trial version according my understanding. Please do pronounce if I took your logic wrongly.
First I build a struct of `int3` to contain 3 integers with some utilities to simplify the coding, then a array of `int3` size 100 in the structure `xxx` (your `x`). Note that the `operator[i]` returns the `xxx[i].p[0]` of ith element, and `operator(i)` returns the `int3 p[3]` for exchange purpose. Both operators have `rvalue` and `lvalue` versions.
The structures: `int3` and `xxx`
#include <iostream>
struct int3
{ int p[3];
int3() = default;
int3(const int3&a) {for (int i=0; i<3; i++) p[i]=a.p[i]; }
int3& operator=(const int3&a) = default;
void print() { std::cout <<"("<< p[0] <<", "<<p[1] <<") "; }
};
struct xxx {
int3 s[100];
int operator[](const int i) const {return s[i].p[0];}
int3 operator()(const int i) const {return s[i];}
int&operator[](const int i) {return s[i].p[0];}
int3&operator()(const int i) {return s[i];}
void print(const int n) {
for(int i=0; i<n; i++) {
std::cout << "No " << i << " = ";
s[i].print();
std::cout << std::endl;
}
}
};
In the test `main()`, I removed the input of `k`. It is not used.
int main()
{
int n, k, i, j;
xxx ox;
int3 q;
std::cout << "input n = ";
std::cin >> n;
while (n>100) {
std::cerr << "Array out of range!\n";
std::cout << "input n = ";
std::cin >> n;
}
for(i=0;i<n;++i) {
std::cout << "a[" << i << "].p[0] ,p[1] = ";
std::cin >> ox.s[i].p[0] >> ox.s[i].p[1];
}
std::cout << "****input list:\n"; ox.print(n);
for(i=0;i<n;++i) {
for(j=0;j<n-i-1;++j) {
if( ox[j] > ox[j+1] ) {
q = ox(j);
ox(j) = ox(j+1);
ox(j+1) = q;
}
}
}
std::cout << "****sorted list:\n"; ox.print(n);
return 0;
}
A test run with `n = 5` in my MSYS2 system
$ ./a.exe
input n = 5
a[0].p[0] ,p[1] = 5 5
a[1].p[0] ,p[1] = 7 7
a[2].p[0] ,p[1] = 3 3
a[3].p[0] ,p[1] = 8 8
a[4].p[0] ,p[1] = 4 4
****input list:
No 0 = (5, 5)
No 1 = (7, 7)
No 2 = (3, 3)
No 3 = (8, 8)
No 4 = (4, 4)
****sorted list:
No 0 = (3, 3)
No 1 = (4, 4)
No 2 = (5, 5)
No 3 = (7, 7)
No 4 = (8, 8)
Good luck!