Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool partial_sort()
- {
- bool is_sorted = true;
- int index, next;
- PlanarPosition temp;
- // compare even columns
- for (int i = 0; i < dim_x - 1; i += 2) {
- for (int j = 0; j < dim_y; j++) {
- index = i + j * dim_x;
- next = index + 1;
- if ((position_matrix[index].x > position_matrix[next].x) ||
- (position_matrix[index].x == position_matrix[next].x && position_matrix[index].y > position_matrix[next].y)) {
- temp = position_matrix[index];
- position_matrix[index] = position_matrix[next];
- position_matrix[next] = temp;
- is_sorted = false;
- }
- }
- }
- // compare odd columns
- for (int i = 1; i < dim_x - 1; i += 2) {
- for (int j = 0; j < dim_y; j++) {
- index = i + j * dim_x;
- next = index + 1;
- if ((position_matrix[index].x > position_matrix[next].x) ||
- (position_matrix[index].x == position_matrix[next].x && position_matrix[index].y > position_matrix[next].y)) {
- temp = position_matrix[index];
- position_matrix[index] = position_matrix[next];
- position_matrix[next] = temp;
- is_sorted = false;
- }
- }
- }
- // compare even rows
- for (int j = 0; j < dim_y - 1; j += 2) {
- for (int i = 0; i < dim_x; i++) {
- index = i + j * dim_x;
- next = index + dim_x;
- if ((position_matrix[index].y > position_matrix[next].y) ||
- (position_matrix[index].y == position_matrix[next].y && position_matrix[index].x > position_matrix[next].x)) {
- temp = position_matrix[index];
- position_matrix[index] = position_matrix[next];
- position_matrix[next] = temp;
- is_sorted = false;
- }
- }
- }
- // compare odd rows
- for (int j = 1; j < dim_y - 1; j += 2) {
- for (int i = 0; i < dim_x; i++) {
- int index = i + j * dim_x;
- next = index + dim_x;
- if ((position_matrix[index].y > position_matrix[next].y) ||
- (position_matrix[index].y == position_matrix[next].y && position_matrix[index].x > position_matrix[next].x)) {
- temp = position_matrix[index];
- position_matrix[index] = position_matrix[next];
- position_matrix[next] = temp;
- is_sorted = false;
- }
- }
- }
- return is_sorted;
- }
- void full_sort()
- {
- while (partial_sort() == false)
- ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement