Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include <time.h>
  6. #include <crtdbg.h>
  7. #include <algorithm>
  8. using namespace std;
  9. struct punkt {
  10. float x;
  11. float y;
  12. };
  13. int comparator(punkt p1, punkt p2) {
  14. double crossprod = p1.y*p2.x - p2.y*p1.x;
  15. if (crossprod > 0.0) return 1;
  16. if (crossprod < 0.0) return -1;
  17. else return 0;
  18. }
  19. int comparatorDoMinimum(punkt p1, punkt p2) {
  20. if (p1.y < p2.y)
  21. return 1;
  22. else {
  23. return 0;
  24. }
  25. }
  26. void Wczytaj(ifstream &file, vector<punkt> &tablica) {
  27. int liczbaPunktow;
  28. if (file){
  29. file >> liczbaPunktow;
  30. tablica.reserve(liczbaPunktow);
  31. for (int i = 0; i < liczbaPunktow; i++) {
  32. punkt zmienna;
  33. file >> zmienna.x >> zmienna.y;
  34. tablica.push_back(zmienna);
  35. }
  36. sort(tablica.begin(), tablica.end(), comparatorDoMinimum);
  37. }
  38. }
  39. vector<punkt> Graham(vector<punkt> &zbior){
  40. vector<punkt> powloka;
  41. powloka.reserve(zbior.size());
  42. auto min=min_element(zbior.begin(), zbior.end(), comparatorDoMinimum);
  43. powloka.push_back(zbior[distance(zbior.begin(), min)]);
  44.  
  45. return powloka;
  46. }
  47.  
  48. int main() {
  49. ifstream zrodlo("D:\\Studia\\II rok\\excercises\\points1.txt", ios::in);
  50. vector<punkt> example;
  51. Wczytaj(zrodlo, example);
  52. for (int i = 0; i < example.size(); i++) {
  53. cout << example[i].x << " " << example[i].y << endl;;
  54. }
  55. cout << endl << endl;
  56. example = Graham(example);
  57. for (int i = 0; i < example.size(); i++) {
  58. cout << example[i].x << " " << example[i].y << endl;;
  59. }
  60. getchar();
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement