diff --git a/graphCountry/graphCountry.sln b/graphCountry/graphCountry.sln new file mode 100644 index 0000000..041a321 --- /dev/null +++ b/graphCountry/graphCountry.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "graphCountry", "graphCountry\graphCountry.vcxproj", "{37B8E2ED-8212-47F8-A168-44A98D5D7568}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {37B8E2ED-8212-47F8-A168-44A98D5D7568}.Debug|x64.ActiveCfg = Debug|x64 + {37B8E2ED-8212-47F8-A168-44A98D5D7568}.Debug|x64.Build.0 = Debug|x64 + {37B8E2ED-8212-47F8-A168-44A98D5D7568}.Debug|x86.ActiveCfg = Debug|Win32 + {37B8E2ED-8212-47F8-A168-44A98D5D7568}.Debug|x86.Build.0 = Debug|Win32 + {37B8E2ED-8212-47F8-A168-44A98D5D7568}.Release|x64.ActiveCfg = Release|x64 + {37B8E2ED-8212-47F8-A168-44A98D5D7568}.Release|x64.Build.0 = Release|x64 + {37B8E2ED-8212-47F8-A168-44A98D5D7568}.Release|x86.ActiveCfg = Release|Win32 + {37B8E2ED-8212-47F8-A168-44A98D5D7568}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7DD259E5-DE48-41D7-844B-628ABC8055CD} + EndGlobalSection +EndGlobal diff --git a/graphCountry/graphCountry/graph.c b/graphCountry/graphCountry/graph.c new file mode 100644 index 0000000..2795514 --- /dev/null +++ b/graphCountry/graphCountry/graph.c @@ -0,0 +1,269 @@ +#include "graph.h" +#include "list.h" +#include "stack.h" +#include +#include +#include + +typedef enum TypeTown { + capital, + notBusy, + busy +}TypeTown; + +typedef struct Node { + int vertex; + TypeTown typeTown; + int onWhichControl; + struct Node* next; + int sizeRoadWithMainVertex; +}Node; + +typedef struct Graph { + int numNode; + struct Node** nodeList; + int numberOfCapitals; +}Graph; + +Graph* createGraph(Error errorCheck, int sizeGraph) { + Graph* graph = calloc(1, sizeof(Graph)); + if (graph == NULL) { + errorCheck = memoryError; + return NULL; + } + graph->numNode = sizeGraph; + graph->nodeList = (Node**)malloc(sizeGraph * sizeof(Node)); + if (graph->nodeList == NULL) { + errorCheck = memoryError; + free(graph); + return NULL; + } + for (int i = 0; i < sizeGraph; ++i) { + graph->nodeList[i] = calloc(1, sizeof(Node*)); + if (graph->nodeList[i] == NULL) { + errorCheck = memoryError; + for (int j = 0; j < i; ++j) { + free(graph->nodeList[j]); + } + free(graph); + return NULL; + } + graph->nodeList[i][0].vertex = i; + graph->nodeList[i][0].next = NULL; + graph->nodeList[i][0].onWhichControl = -1; + graph->nodeList[i][0].typeTown = notBusy; + graph->nodeList[i][0].sizeRoadWithMainVertex = 0; + } + + return graph; +} + +void helpToAddRoad(Graph* graph, int firstNode, int secondNode, int sizeRoad, Error errorCheck) { + Node* walkerInGraph = graph->nodeList[firstNode]; + while (walkerInGraph->next != NULL) { + walkerInGraph = walkerInGraph->next; + } + Node* temp = calloc(1, sizeof(Node)); + if (temp == NULL) { + errorCheck = memoryError; + for (int i = 0; i < graph->numNode; ++i) { + free(graph->nodeList[i]); + } + free(graph); + return; + } + temp->sizeRoadWithMainVertex = sizeRoad; + temp->vertex = secondNode; + temp->next = NULL; + temp->onWhichControl = -1; + temp->typeTown = notBusy; + walkerInGraph->next = temp; +} + +void addRoad(Graph* graph, Error errorCheck, int firstNode, int secondNode, int sizeRoad) { + if (graph == NULL) { + errorCheck = nullGraph; + return; + } + + if (firstNode >= graph->numNode || secondNode >= graph->numNode) { + errorCheck = outOfGraph; + for (int i = 0; i < graph->numNode; ++i) { + free(graph->nodeList[i]); + } + free(graph); + return; + } + + if (firstNode == secondNode) { + graph->nodeList[firstNode]->sizeRoadWithMainVertex = sizeRoad; + return; + } + + helpToAddRoad(graph, firstNode, secondNode, sizeRoad, errorCheck); + if (errorCheck != ok) { + clearGraph(graph); + return; + } + + if (firstNode != secondNode) { + helpToAddRoad(graph, secondNode, firstNode, sizeRoad, errorCheck); + if (errorCheck != ok) { + clearGraph(graph); + return; + } + } +} + +void printGraph(Graph* graph) { + if (graph == NULL) { + return; + } + for (int i = 0; i < graph->numNode; ++i) { + Node* walker = graph->nodeList[i]; + printf("%d : ", walker->vertex); + if (walker->sizeRoadWithMainVertex != 0) { + printf("-%d- ", walker->sizeRoadWithMainVertex); + } + walker = walker->next; + while (walker != NULL) { + printf("%d ", walker->vertex); + printf("(%d) ", walker->sizeRoadWithMainVertex); + walker = walker->next; + } + printf("\n"); + } +} + +void addCapital(Graph* graph, int numberCapital, Error checkError) { + if (graph == NULL) { + checkError = anotherError; + return; + } + + if (numberCapital >= graph->numNode) { + checkError = anotherError; + clearGraph(graph); + return; + } + + graph->nodeList[numberCapital]->typeTown = capital; + Node* walker = graph->nodeList[numberCapital]->next; + while (walker != NULL) { + Node* newWalker = graph->nodeList[walker->vertex]; + while (newWalker->vertex != numberCapital) { + newWalker = newWalker->next; + } + newWalker->typeTown = capital; + walker = walker->next; + } + ++graph->numberOfCapitals; +} + +void recursionAddTown(Graph* graph, int* min, int* numberTown, int index, const int numberCapital, int localMin, Error errorCheck) { + Node* walker = graph->nodeList[index]->next; + + while (walker != NULL) { + if (walker->typeTown == busy && walker->onWhichControl == numberCapital) { + localMin += walker->sizeRoadWithMainVertex; + recursionAddTown(graph, min, numberTown, walker->vertex, numberCapital, localMin, errorCheck); + } else if (walker->typeTown == notBusy) { + localMin += walker->sizeRoadWithMainVertex; + if (localMin < *min || *min == -1) { + *min = localMin; + *numberTown = walker->vertex; + } + localMin -= walker->sizeRoadWithMainVertex; + } + walker = walker->next; + } + +} + +void addTown(Graph* graph, int numberCapital, Error errorCheck, bool* isAdded) { + if (graph == NULL) { + errorCheck = nullGraph; + return; + } + int min = -1; + int numberAddedTown = numberCapital; + int index = numberCapital; + recursionAddTown(graph, &min, &numberAddedTown, index, numberCapital, 0, errorCheck); + if (min != -1) { + graph->nodeList[numberAddedTown]->typeTown = busy; + graph->nodeList[numberAddedTown]->onWhichControl = numberCapital; + Node* walker = graph->nodeList[numberAddedTown]->next; + while (walker != NULL) { + Node* anotherWalker = graph->nodeList[walker->vertex]; + while (anotherWalker->vertex != numberAddedTown) { + anotherWalker = anotherWalker->next; + } + anotherWalker->typeTown = busy; + anotherWalker->onWhichControl = numberCapital; + walker = walker->next; + } + *isAdded = true; + } +} + +void toControllTowns(Graph* graph, Error errorCheck) { + if (graph == NULL) { + errorCheck = nullGraph; + return; + } + int i = 0; + int indexCapital = 0; + bool isAdded = false; + while (i < graph->numNode - graph->numberOfCapitals) { + while (graph->nodeList[indexCapital]->typeTown != capital) { + ++indexCapital; + if (indexCapital == graph->numNode) { + indexCapital = 0; + } + } + isAdded = false; + addTown(graph, indexCapital, errorCheck, &isAdded); + ++indexCapital; + if (indexCapital == graph->numNode) { + indexCapital = 0; + } + if (isAdded) { + ++i; + } + } +} + +void returnArrayWithControlledTowns(Graph* graph, Error errorCheck, bool** controlledTownsArray) { + int indexSizeTowns = 0; + Node* walker = graph->nodeList[0]; + while (indexSizeTowns < graph->numNode) { + while (walker != NULL) { + if (walker->typeTown == capital) { + controlledTownsArray[walker->vertex][0] = true; + } + else { + controlledTownsArray[walker->onWhichControl][walker->vertex + 1] = true; + } + walker = walker->next; + } + walker = graph->nodeList[indexSizeTowns]; + ++indexSizeTowns; + } + return controlledTownsArray; +} + +void clearGraph(Graph* graph) { + int i = 0; + while (i < graph->numNode) { + Node* walker = graph->nodeList[i]->next; + while (walker != NULL) { + Node* temp = walker->next; + free(walker); + walker = temp; + } +// free(graph->nodeList[i]); + ++i; + } + free(graph->nodeList); + free(graph); +} \ No newline at end of file diff --git a/graphCountry/graphCountry/graph.h b/graphCountry/graphCountry/graph.h new file mode 100644 index 0000000..63e2719 --- /dev/null +++ b/graphCountry/graphCountry/graph.h @@ -0,0 +1,26 @@ +#pragma once +#include + +typedef struct Graph Graph; +typedef enum Error { + memoryError, + anotherError, + nullGraph, + outOfGraph, + fileError, + ok, +}Error; + +Graph* createGraph(Error errorCheck, int sizeGraph); + +void addRoad(Graph* graph, Error errorCheck, int firstNode, int secondNode, int sizeRoad); + +void printGraph(Graph* graph); + +void toControllTowns(Graph* graph, Error errorCheck); + +void addCapital(Graph* graph, int numberCapital, Error checkError); + +void returnArrayWithControlledTowns(Graph* graph, Error errorCheck, bool** controlledTownsArray); + +void clearGraph(Graph* graph); \ No newline at end of file diff --git a/graphCountry/graphCountry/graphCountry.vcxproj b/graphCountry/graphCountry/graphCountry.vcxproj new file mode 100644 index 0000000..67e79fc --- /dev/null +++ b/graphCountry/graphCountry/graphCountry.vcxproj @@ -0,0 +1,157 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {37b8e2ed-8212-47f8-a168-44a98d5d7568} + graphCountry + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + false + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/graphCountry/graphCountry/graphCountry.vcxproj.filters b/graphCountry/graphCountry/graphCountry.vcxproj.filters new file mode 100644 index 0000000..3c9d096 --- /dev/null +++ b/graphCountry/graphCountry/graphCountry.vcxproj.filters @@ -0,0 +1,44 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + + + Исходные файлы + + + Исходные файлы + + + + + Исходные файлы + + + Исходные файлы + + + \ No newline at end of file diff --git a/graphCountry/graphCountry/list.c b/graphCountry/graphCountry/list.c new file mode 100644 index 0000000..ae0be5d --- /dev/null +++ b/graphCountry/graphCountry/list.c @@ -0,0 +1,113 @@ +#include "list.h" +#include "graph.h" +#include +#include + +typedef enum Error { + ok, + error +}; + +typedef struct Town { + int numberTown; + struct Town* nextTown; + int sizeWay; +}Town; + +typedef struct Capital { + struct Capital* nextCapital; + struct Town* firstTown; + int numberCapital; +} Capital; + +typedef struct List { + struct Capital* firstCapital; +} List; + +List* createList(Error errorCheck) { + List* list = calloc(1, sizeof(List)); + if (list == NULL) { + errorCheck = error; + return NULL; + } + return list; +} + +Error addCapitalToList(List* list, int numberCapital) { + if (list == NULL) { + return error; + } + Capital* temp = calloc(1, sizeof(Capital)); + if (temp == NULL) { + return error; + } + temp->numberCapital = numberCapital; + temp->firstTown = NULL; + temp->nextCapital = NULL; + if (list->firstCapital == NULL) { + list->firstCapital = temp; + return ok; + } + Capital* walker = list->firstCapital; + while (walker->nextCapital != NULL) { + walker = walker->nextCapital; + } + walker->nextCapital = temp; + return ok; +} + +void clearList(List* list) { + if (list == NULL) { + return; + } + + if (list->firstCapital == NULL) { + free(list); + list = NULL; + return; + } + + while (list->firstCapital != NULL) { + Capital* walker = list->firstCapital; + if (walker->nextCapital == NULL) { + free(walker->firstTown); + free(walker); + free(list); + } + while (walker->nextCapital->nextCapital != NULL) { + walker = walker->nextCapital; + } + free(walker->nextCapital->firstTown); + free(walker->nextCapital); + } +} + +Error addTownToCapital(int numberCapital, int sizeWay, int numberTown, List* list) { + if (list == NULL) { + return error; + } + Capital* walker = list->firstCapital; + while (walker != NULL) { + if (walker->numberCapital == numberCapital) { + Town* newTown = calloc(1, sizeof(Town)); + if (newTown == NULL) { + return error; + } + newTown->sizeWay = sizeWay; + newTown->numberTown = numberTown; + newTown->nextTown = NULL; + if (walker->firstTown != NULL) { + Town* temp = walker->firstTown; + while (temp->nextTown != NULL) { + temp = temp->nextTown; + } + temp->nextTown = newTown; + return ok; + } + walker->firstTown = newTown; + return ok; + } + walker = walker->nextCapital; + } + return error; +} \ No newline at end of file diff --git a/graphCountry/graphCountry/list.h b/graphCountry/graphCountry/list.h new file mode 100644 index 0000000..ee5052e --- /dev/null +++ b/graphCountry/graphCountry/list.h @@ -0,0 +1,12 @@ +#pragma once + +typedef struct List List; +typedef enum Error Error; + +List* createList(Error errorCheck); + +Error addCapitalToList(List* list, int numberCapital); + +void clearList(List* list); + +Error addTownToCapital(int numberCapital, int sizeWay, int numberTown, List* list); \ No newline at end of file diff --git a/graphCountry/graphCountry/main.c b/graphCountry/graphCountry/main.c new file mode 100644 index 0000000..eabbcfa --- /dev/null +++ b/graphCountry/graphCountry/main.c @@ -0,0 +1,147 @@ +#include "graph.h" +#include "test.h" +#include +#include +#include + +Error workWithGraph(const char* fileName) { + Error errorCheck = ok; + FILE* file = fopen(fileName, "r"); + if (file == NULL) { + return fileError; + } + int numberOfTowns = 0; + if (fscanf_s(file, "%d", &numberOfTowns) != 1) { + fclose(file); + return fileError; + } + if (numberOfTowns == INT_MAX) { + return anotherError; + } + Graph* graph = createGraph(errorCheck, numberOfTowns); + + int numberOfRoads = 0; + if (fscanf_s(file, "%d", &numberOfRoads) != 1) { + fclose(file); + return fileError; + } + int firstTown = 0; + int secondTown = 0; + int sizeRoad = 0; + for (int i = 0; i < numberOfRoads; ++i) { + if (fscanf_s(file, "%d %d %d", &firstTown, &secondTown, &sizeRoad) != 3) { + fclose(file); + return fileError; + } + addRoad(graph, errorCheck, firstTown, secondTown, sizeRoad); + if (errorCheck != ok) { + clearGraph(graph); + fclose(file); + return errorCheck; + } + } + int numberOfCapitals = 0; + if (fscanf_s(file, "%d", &numberOfCapitals) != 1) { + clearGraph(graph); + fclose(file); + return fileError; + } + int numberCapital; + for (int i = 0; i < numberOfCapitals; ++i) { + if (fscanf_s(file, "%d", &numberCapital) != 1){ + clearGraph(graph); + fclose(file); + return fileError; + } + addCapital(graph, numberCapital, errorCheck); + } + fclose(file); + toControllTowns(graph, errorCheck); + if (errorCheck != ok) { + clearGraph(graph); + return errorCheck; + } + int sizeArray = 0; + bool** arrayControlledTowns = (bool**)malloc((numberOfTowns + 1) * sizeof(bool*)); + if (arrayControlledTowns == NULL) { + clearGraph(graph); + return memoryError; + } + for (int i = 0; i < numberOfTowns + 1; ++i) { + arrayControlledTowns[i] = calloc((numberOfTowns + 1),sizeof(bool*)); + if (arrayControlledTowns[i] == NULL) { + for (int j = 0; j < i; ++j) { + free(arrayControlledTowns[j]); + } + free(arrayControlledTowns); + clearGraph(graph); + return memoryError; + } + } + returnArrayWithControlledTowns(graph, errorCheck, arrayControlledTowns); + if (errorCheck != ok) { + for (int i = 0; i < numberOfTowns + 1; ++i) { + free(arrayControlledTowns[i]); + } + free(arrayControlledTowns); + clearGraph(graph); + return errorCheck; + } + + for (int i = 0; i < numberOfTowns + 1; ++i) { + if (arrayControlledTowns[i][0]) { + printf("%d: ", i); + for (int j = 1; j < numberOfTowns + 1; ++j) { + if (arrayControlledTowns[i][j]) { + printf("%d ", j - 1); + } + } + printf("\n"); + } + } + for (int i = 0; i < numberOfTowns + 1; ++i) { + free(arrayControlledTowns[i]); + } + free(arrayControlledTowns); + clearGraph(graph); + return ok; +} + +int main() { + if (test()) { + printf("Tests correct!\n"); + } else { + printf("Error!\n"); + return -1; + } + printf("Input fileName, no more than 100 characters\n"); + char fileName[100] = { '\0' }; + char checkScanf = scanf_s("%s", &fileName, 99); + while (checkScanf != 1) { + while (getchar() != '\n') { + } + printf("ERROR\n"); + checkScanf = scanf_s("%s", &fileName, 99); + } + Error errorCheck = workWithGraph(fileName); + switch (errorCheck) + { + case(ok): + return 0; + case(memoryError): + printf("Error with memory\n"); + return -1; + case(anotherError): + printf("Error\n"); + return -1; + case(nullGraph): + printf("Error with null graph\n"); + return -1; + case(outOfGraph): + printf("Error going beyond the graph\n"); + return -1; + case(fileError): + printf("Error with file\n"); + return -1; + } +} \ No newline at end of file diff --git a/graphCountry/graphCountry/newTest.txt b/graphCountry/graphCountry/newTest.txt new file mode 100644 index 0000000..08e507e --- /dev/null +++ b/graphCountry/graphCountry/newTest.txt @@ -0,0 +1,10 @@ +6 5 +0 2 1 +1 2 1 +2 3 1 +2 4 1 +4 5 1 +2 +0 +5 +// \ No newline at end of file diff --git a/graphCountry/graphCountry/stack.c b/graphCountry/graphCountry/stack.c new file mode 100644 index 0000000..2cb6881 --- /dev/null +++ b/graphCountry/graphCountry/stack.c @@ -0,0 +1,65 @@ +#include "stack.h" +#include +#include +#include + +typedef enum Error { + ok, + error +}Error; + +typedef struct ElementStack { + struct ElementStack* next; + int value; +} ElementStack; + +typedef struct Stack { + struct ElementStack* head; +}Stack; + +int pushElements(Stack* stack, int value) { + ElementStack* temp = malloc(sizeof(ElementStack)); + if (temp == NULL) { + return -1; + } + temp->value = value; + temp->next = stack; + + stack = temp; + return 0; +} + +bool isEmpty(Stack* stack) { + return stack == NULL || stack->head == NULL; +} + +void clear(Stack* stack) { + if (stack == NULL) { + return; + } + while (!isEmpty(stack)) { + popElements(stack, NULL); + } +} + +int popElements(Stack* stack, Error checkError) { + if (stack == NULL || stack->head) { + checkError = error; + return -1; + } + + int value = stack->head->value; + + ElementStack* temp = stack->head->next; + free(stack->head); + stack->head = temp; + + return value; +} + +int top(Stack* stack) { + if (stack == NULL || stack->head == NULL) { + return -1; + } + return stack->head->value; +} \ No newline at end of file diff --git a/graphCountry/graphCountry/stack.h b/graphCountry/graphCountry/stack.h new file mode 100644 index 0000000..f8287ee --- /dev/null +++ b/graphCountry/graphCountry/stack.h @@ -0,0 +1,11 @@ +#pragma once +#include + +typedef struct Stack Stack; +typedef enum Error Error; + +int pushElements(Stack* stack, int value); +bool isEmpty(Stack* stack); +void clear(Stack* stack); +int popElements(Stack* stack, Error checkError); +int top(Stack* stack); \ No newline at end of file diff --git a/graphCountry/graphCountry/test.c b/graphCountry/graphCountry/test.c new file mode 100644 index 0000000..842df04 --- /dev/null +++ b/graphCountry/graphCountry/test.c @@ -0,0 +1,73 @@ +#include "graph.h" +#include "test.h" +#include + +bool test() { + Error errorCheck = ok; + Graph* graph = createGraph(errorCheck, 6); + if (errorCheck != ok) { + return false; + } + addRoad(graph, errorCheck, 0, 1, 10); + if (errorCheck != ok) { + return false; + } + addRoad(graph, errorCheck, 0, 2, 12); + if (errorCheck != ok) { + return false; + } + addRoad(graph, errorCheck, 1, 3, 10); + if (errorCheck != ok) { + return false; + } + addRoad(graph, errorCheck, 1, 4, 14); + if (errorCheck != ok) { + return false; + } + addRoad(graph, errorCheck, 2, 5, 16); + if (errorCheck != ok) { + return false; + } + addRoad(graph, errorCheck, 3, 5, 21); + if (errorCheck != ok) { + return false; + } + addCapital(graph, 1, errorCheck); + if (errorCheck != ok) { + return false; + } + addCapital(graph, 5, errorCheck); + if (errorCheck != ok) { + return false; + } + toControllTowns(graph, errorCheck); + if (errorCheck != ok) { + return false; + } + bool** arrayControlledTowns = (bool**)malloc(7 * sizeof(bool*)); + if (arrayControlledTowns == NULL) { + clearGraph(graph); + return false; + } + for (int i = 0; i < 7; ++i) { + arrayControlledTowns[i] = calloc(7, sizeof(bool*)); + if (arrayControlledTowns[i] == NULL) { + for (int j = 0; j < i; ++j) { + free(arrayControlledTowns[j]); + } + free(arrayControlledTowns); + return false; + } + } + returnArrayWithControlledTowns(graph, errorCheck, arrayControlledTowns); + if (errorCheck != ok) { + for (int i = 0; i < 7; ++i) { + free(arrayControlledTowns[i]); + } + free(arrayControlledTowns); + clearGraph(graph); + return false; + } + return arrayControlledTowns[1][0] && arrayControlledTowns[1][1] && arrayControlledTowns[1][4] + && arrayControlledTowns[1][5] && arrayControlledTowns[5][0] && arrayControlledTowns[5][3]; +} \ No newline at end of file diff --git a/graphCountry/graphCountry/test.h b/graphCountry/graphCountry/test.h new file mode 100644 index 0000000..755c9bd --- /dev/null +++ b/graphCountry/graphCountry/test.h @@ -0,0 +1,5 @@ +#pragma once +#include + +// +bool test(void); \ No newline at end of file diff --git a/graphCountry/graphCountry/test.txt b/graphCountry/graphCountry/test.txt new file mode 100644 index 0000000..2dfd5e1 --- /dev/null +++ b/graphCountry/graphCountry/test.txt @@ -0,0 +1,10 @@ +6 6 +0 1 10 +0 2 12 +1 3 14 +1 4 15 +2 5 16 +3 5 21 +2 +1 +5 \ No newline at end of file