Загрузить файлы в «/»
This commit is contained in:
commit
5caf37e303
3 changed files with 179 additions and 0 deletions
70
graph.hpp
Normal file
70
graph.hpp
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
#pragma once
|
||||||
|
#include "tools.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
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){
|
||||||
|
|
||||||
|
|
||||||
|
}
|
37
main.graph.cpp
Normal file
37
main.graph.cpp
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <ctime>
|
||||||
|
#include "tools.hpp"
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
72
tools.hpp
Normal file
72
tools.hpp
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
#pragma once
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <cstring>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
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<char*>(input.c_str()), " ");
|
||||||
|
while (token) {
|
||||||
|
kusochki[i++] = std::stoi(std::string(token));
|
||||||
|
token = strtok(NULL, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue