Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.1 kB
4
Indexable
Never
#include <iostream>
#include <cmath>

using namespace std;

struct Point {
    double x, y, z;
    Point* next;
};

Point* head = nullptr;

void insertPoint(double x, double y, double z) {
    Point* newPoint = new Point;
    newPoint->x = x;
    newPoint->y = y;
    newPoint->z = z;
    newPoint->next = nullptr;

    if (head == nullptr) {
        head = newPoint;
    } else {
        Point* current = head;
        while (current->next != nullptr) {
            current = current->next;
        }
        current->next = newPoint;
    }
}

void sortList() {
    Point* current = head;
    Point* index = nullptr;
    double tempX, tempY, tempZ;

    if (head == nullptr) {
        return;
    } else {
        while (current != nullptr) {
            index = current->next;
            while (index != nullptr) {
                if (current->x > index->x ||
                    (current->x == index->x && current->y > index->y) ||
                    (current->x == index->x && current->y == index->y && current->z > index->z)) {
                    tempX = current->x;
                    tempY = current->y;
                    tempZ = current->z;
                    current->x = index->x;
                    current->y = index->y;
                    current->z = index->z;
                    index->x = tempX;
                    index->y = tempY;
                    index->z = tempZ;
                }
                index = index->next;
            }
            current = current->next;
        }
    }
}

void printList() {
    Point* current = head;
    while (current != nullptr) {
        cout << current->x << " " << current->y << " " << current->z << endl;
        current = current->next;
    }
}

void run() {
    int n;
    cin >> n;

    double x, y, z;
    for (int i = 0; i < n; i++) {
        cin >> x >> y >> z;
        insertPoint(x, y, z);
    }

    sortList();
    printList();
}

int main() {
    int* a = new int[256];
    int* b = new int[256];
    delete[] a;
    run();
    delete[] b;
    return 0;
}
Leave a Comment