Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main:
- #include <iostream>
- int main()
- {
- }
- list.h:
- #pragma once
- #include "Point.h"
- class List
- {
- private:
- struct Node
- {
- Point point;
- Node* next;
- Node(const Point point) : next(nullptr), point(point) {}
- };
- Node* first;
- size_t size;
- Node* find(const size_t index);
- void pop(const size_t index);
- void push(const Point& point, const size_t index);
- public:
- List();
- ~List();
- };
- List .cpp:
- #include "List.h"
- List::List() : first(nullptr), size(0) {}
- List::Node* List::find(const size_t index)
- {
- List::Node* it = first;
- for (size_t i = 0; i < index; i++)
- {
- it = it->next;
- }
- return it;
- }
- //V nie wiem czy to tu mialo byc dopisane
- void List::pop(const size_t index)
- {
- if (index == 0) {
- List::Node* node = find(index);
- first = node->next;
- delete node;
- size--;
- }
- else {
- List::Node* to_pop = find(index);
- List::Node* last = find(index - 1);
- last->next = to_pop->next;
- delete to_pop;
- size--
- }
- }
- void List::push(const Point& point, size_t index)
- {
- List::Node* node = new List::Node(point);
- if (index == 0)
- {
- node->next = first;
- first = node;
- }
- else
- {
- List::Node* last = find(index - 1);
- node->next = last->next;
- last->next = node;
- }
- size++;
- }
- point.h:
- #pragma once
- struct Point {
- double x, y, z;
- Point() : x(0.0), y(0.0), z(0.0) {}
- Point(double x, double y, double z) : x(x), y(y), z(z) {}
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement