commit 5caf37e30355443986f6b4c0c28805fa942fd518 Author: glazirEgorGeekovich Date: Sun May 25 13:39:04 2025 +0300 Загрузить файлы в «/» diff --git a/graph.hpp b/graph.hpp new file mode 100644 index 0000000..71fe667 --- /dev/null +++ b/graph.hpp @@ -0,0 +1,70 @@ +#pragma once +#include "tools.hpp" +#include +#include +#include +#include + +struct Edge; +struct Node { + Edge *nextNodes; + + tls::Index index; + tls::Value value; +}; + +struct Edge { + tls::Weight wght; + Node *receiver; + + Edge() { + wght = 1; + receiver = new Node; + } +}; + +struct Graph { + Node *firstNode; + tls::Size size; + + Graph() { + firstNode = new Node; + size = 1; + } + + //void link(tls::Index origin, tls::Index *stocks); + void fill(tls::Index origin); + + +}; + +void Graph::fill(tls::Index origin){ + if (origin == this->size) return; + + + tls::DiEgo tmp; + tmp.strock(origin); + + + + // std::cout << "Got numbers: "; + // for (int j = 0; j < tmp.size_kusochki; j++) { + // std::cout << tmp.kusochki[j] << " "; + // } + + Graph* template_graph; + for (tls::Index k = 0; k < tmp.size_kusochki; k++){ + + this->firstNode->nextNodes = new Edge; + this->firstNode->nextNodes->receiver->index = tmp.kusochki[k]; + fill(); + } + + delete[] tmp.kusochki; + +} + +void link(tls::Index origin, tls::Index *stocks){ + + +} \ No newline at end of file diff --git a/main.graph.cpp b/main.graph.cpp new file mode 100644 index 0000000..001b793 --- /dev/null +++ b/main.graph.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include "tools.hpp" +#include + +#include "graph.hpp" + +// int countNumbers(const std::string& s) { +// std::stringstream ss(s); +// int number; +// int count = 0; + +// while (ss >> number) { +// count++; +// } +// return count; +// } +// std::string& strock(){ +// std::string input; +// std::cout << "Enter links for Node " << '\t'<< std::endl; +// std::getline(std::cin, input); +// return input; +// } + +int main(){ + Graph graph; + std :: cout << "Enter size: "; + std::cin >> graph.size; + graph.fill(1); + + + + + std::system("pause"); + return 0; +} \ No newline at end of file diff --git a/tools.hpp b/tools.hpp new file mode 100644 index 0000000..95e34af --- /dev/null +++ b/tools.hpp @@ -0,0 +1,72 @@ +#pragma once +#include +#include +#include +#include + +namespace tls { + + using Weight = float; + using Value = int; + using Index = int; + using Size = int; + + struct DiEgo { + + public: + Index *kusochki; + Size size_kusochki; + + void strock(tls::Index origin); + + DiEgo() { + kusochki = nullptr; + size_kusochki = 0; + } + // ~DiEgo() { + // delete[] kusochki; + // // delete this; + // } + + }; + +} + +void tls::DiEgo::strock(tls::Index origin) { + + std::string input; + + // Очищаем буфер от возможных остатков + std::cin.clear(); + + // Читаем всю строку + std::cout << "Enter links for Node " << origin << ": "; + std::getchar(); // Проглотим символ новой строки + std::cin >> std::noskipws; // Отключаем пропуск пробелов + + // Читаем символы до символа новой строки + char ch; + while (std::cin.get(ch) && ch != '\n') { + input += ch; + } + + //Подсчет количества чисел в строке + size_kusochki = 0; + for (char c : input) { + if (c == ' ') size_kusochki++; + } + size_kusochki++; // Добавляем 1, так как после последнего числа нет пробела + if (size_kusochki == 0) return; //выход из рекурсии + + + kusochki = new int[size_kusochki]; + + // Разбиваем строку и записываем числа в массив + int i = 0; + char* token = strtok(const_cast(input.c_str()), " "); + while (token) { + kusochki[i++] = std::stoi(std::string(token)); + token = strtok(NULL, " "); + } + +} \ No newline at end of file