Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <time.h>
- #include <crtdbg.h>
- #include <algorithm>
- using namespace std;
- struct punkt {
- float x;
- float y;
- };
- int comparator(punkt p1, punkt p2) {
- double crossprod = p1.y*p2.x - p2.y*p1.x;
- if (crossprod > 0.0) return 1;
- if (crossprod < 0.0) return -1;
- else return 0;
- }
- int comparatorDoMinimum(punkt p1, punkt p2) {
- if (p1.y < p2.y)
- return 1;
- else {
- return 0;
- }
- }
- void Wczytaj(ifstream &file, vector<punkt> &tablica) {
- int liczbaPunktow;
- if (file){
- file >> liczbaPunktow;
- tablica.reserve(liczbaPunktow);
- for (int i = 0; i < liczbaPunktow; i++) {
- punkt zmienna;
- file >> zmienna.x >> zmienna.y;
- tablica.push_back(zmienna);
- }
- sort(tablica.begin(), tablica.end(), comparatorDoMinimum);
- }
- }
- vector<punkt> Graham(vector<punkt> &zbior){
- vector<punkt> powloka;
- powloka.reserve(zbior.size());
- auto min=min_element(zbior.begin(), zbior.end(), comparatorDoMinimum);
- powloka.push_back(zbior[distance(zbior.begin(), min)]);
- return powloka;
- }
- int main() {
- ifstream zrodlo("D:\\Studia\\II rok\\excercises\\points1.txt", ios::in);
- vector<punkt> example;
- Wczytaj(zrodlo, example);
- for (int i = 0; i < example.size(); i++) {
- cout << example[i].x << " " << example[i].y << endl;;
- }
- cout << endl << endl;
- example = Graham(example);
- for (int i = 0; i < example.size(); i++) {
- cout << example[i].x << " " << example[i].y << endl;;
- }
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement