Разработка программы формирования матрицы смежности

Курсовой проект - Компьютеры, программирование

Другие курсовые по предмету Компьютеры, программирование

leOutput)<< "Вершины, смежные с вершиной, имеющей максимальную степень исхода, удалены," << endl

nextArc;sideNode;

}(fileOutput) {.close();

*out << endl << endl;<< "Запись в файл успешно завершена!" << endl;

}_STAGE = START_EXECUTION;;

};SOME_ACTIONS_PERFORMED:

cout << "Список доступных действий:" << endl;<< PRINT_NEIBORHOODS << " - вывести список окрестностей" << endl;<< MAKE_ADJACENCY_MATRIX << " - соствить и вывести матрицу смежности" << endl;<< SAVE_NEW_GRAPH << " - сохранить новый граф" << endl;<< RESTART_PROGRAM << " - начать выполнение программы сначала" << endl;

cout << EXIT << " - выход" << endl;

_input(action, SOME_ACTIONS_MODE);(action) {PRINT_NEIBORHOODS:

printNeiborhoodsList(firstArc, out, NUM_VERTEX, false, "Список окрестностей графа после удаления вершин, смежных с вершиной, имеющей максимальную степень исхода:");

*out << endl << endl;(fileOutput)

cout << "Список окрестностей нового графа записан в файл." << endl;;MAKE_ADJACENCY_MATRIX:= completeAdjacencyMatrix(firstArc, NUM_VERTEX);(adjacencyMatrix, NUM_VERTEX, out, "Матрица смежности нового графа: ");(adjacencyMatrix, NUM_VERTEX);

*out << endl << endl;

if(fileOutput)<< "Матрица смежности нового графа записана в файл." << endl;;SAVE_NEW_GRAPH:

cout << "Введите имя нового графа: ";

_input(fileForOutputName);(!saveGraph(fileForOutputName, firstArc, NUM_VERTEX))

cout nextArc;sideNode;

}(fileOutput) {.close();

*out << endl << endl;

cout << "Запись в файл успешно завершена!" << endl;

}_STAGE = START_EXECUTION;;

}

}("pause");();

}*assembleGraph(int &NUM_VERTEX, ostream *stream) {*firstNode = NULL, *lastNode = NULL, *currentNode;getArcData(string graphName, int &NUM_VERTEX, DirectedGraph *&lastNode, ostream *stream = &cout);graphName;<< "Имя графа: ";

_input(graphName);(getArcData(graphName, NUM_VERTEX, firstNode, stream)) {= firstNode;(getArcData(graphName, NUM_VERTEX, lastNode)) {>previousArc = currentNode;>nextArc = NULL;>nextArc = lastNode;= lastNode;

}

}firstNode;

}getArcData(string graphName, int &NUM_VERTEX, DirectedGraph *&lastNode, ostream *stream = &cout) {fstream fileForReadGraph;filePath = "graphs/";inVertexId;int counter = 0;sideChar;bool firstIn = true;fileExists(string fileName);openFile(string fileName, char mode);(firstIn) {(!fileExists(filePath+graphName+".txt")) {

cout << "Графа с таким именем не существует!" << endl << "Будет загружен стандартный файл . . ." << endl;= "default";

}= openFile(filePath+graphName+".txt", i);

*stream << "Граф " << graphName << endl;= false;++;

}(fileForReadGraph.eof()) {= true;_VERTEX = counter;= 0;.close();false;

}= (DirectedGraph*) new (DirectedGraph);>previousArc = NULL;>nextArc = NULL;(lastNode == NULL) {

cout << "Память не выделилась!" << endl << "Выполнение программы завершено . . .";

Sleep(1000);(1);

>inVertexId;>oneArc.inVertexId=inVertexId;>oneArc.outVertexId=counter;=fileForReadGraph.get();(sideChar==\n)++;true;">}>> inVertexId;>oneArc.inVertexId = inVertexId;>oneArc.outVertexId = counter;= fileForReadGraph.get();(sideChar == \n)++;true;

oneArc.outVertexId==counter)){++;=firstNode->nextArc;">}findVertexAndPrintNewList(DirectedGraph *firstNode, int NUM_VERTEX, int &maxLevelOfVertex, ostream *stream) {counter, inVertexCounter, vertexWithMaxLevel = 0;= 0;(counter = 1; counter nextArc;

}

*stream maxLevelOfVertex) {= inVertexCounter;= counter;

}

}

*stream << "Вершина с максимальной степенью исхода: " << vertexWithMaxLevel << endl;vertexWithMaxLevel;

}foundInArray(int value, int *arr, int rightBound) {counter, middle, leftBound = 0;((value > arr[rightBound]) || (value 1) {= (rightBound+leftBound)/2;(arr[middle] < value)= middle;= middle;

}(counter = 0; counter <= rightBound; counter++) {(arr[counter] == value)counter;

}-1;

}openFile(string fileName, char mode) {filePointer;(mode) {i:filePointer.open(fileName, ios_base::in); break;o:filePointer.open(fileName, ios_base::out); break;a:filePointer.open(fileName, ios_base::app); break;

}filePointer;

}removeNode(DirectedGraph *node, DirectedGraph *&firstNode) {((node->previousArc != NULL) && (node->nextArc != NULL)) {>previousArc->nextArc = node->nextArc;>nextArc->previousArc = node->previousArc;

} else if((node->previousArc == NULL) && (node->nextArc != NULL)) {>nextArc->previousArc = NULL;= node->nextArc;

} else if((node->previousArc != NULL) && (node->nextArc == NULL)) {>previousArc->nextArc = NULL;

} else if((node->previousArc == NULL) && (node->nextArc == NULL)) {= NULL;

}node;

}saveGraph(string fileName, DirectedGraph *firstNode, int NUM_VERTEX) {fileExists(string fileName);printNeiborhoodsList(DirectedGraph *firstNode, ostream *stream, int NUM_VERTEX, bool saveMode, string title = "");openFile(string fileName, char mode);(fileExists("graphs/"+fileName+".txt")) return false;file;= openFile("graphs/"+fileName+".txt", o);(firstNode, &file, NUM_VERTEX, true);true;

oneArc.outVertexId!=vertexId))=currentNode->nextArc;=1;=newint[vertexLevel];[0]=currentNode->oneArc.inVertexId;>oneArc.inVertexId=0;=currentNode->nextArc;((currentNode!=NULL)&&(currentNode->oneArc.outVertexId==vertexId)){[counter]=currentNode->oneArc.inVertexId;=currentNode;=currentNode->nextArc;(nodePointer,firstArc);++;">}removeAdjacentVertex(DirectedGraph *&firstArc, int NUM_VERTEX, int vertexId, int vertexLevel) {*currentNode, *nodePointer, *sidePointer;counter, currentId, *adjacentVertex, *newVertexId, NOT_FOUND = -1;noOneBefore;removeNode(DirectedGraph *node, DirectedGraph *&firstNode);foundInArray(int value, int *arr, int rightBound);= firstArc;((currentNode != NULL) && (currentNode->oneArc.outVertexId != vertexId))= currentNode->nextArc;= 1;= new int [vertexLevel];[0] = currentNode->oneArc.inVertexId;>oneArc.inVertexId = 0;= currentNode->nextArc;((currentNode != NULL) && (currentNode->oneArc.outVertexId == vertexId)) {[counter] = currentNode->oneArc.inVertexId;= currentNode;= currentNode->nextArc;(nodePointer, firstArc);++;

oneArc.outVertexId;(foundInArray(currentId,adjacentVertex,vertexLevel-1)!=NOT_FOUND){((currentNode!=NULL)&&(currentNode->oneArc.outVertexId==currentId)){=currentNode;=currentNode->nextArc;(nodePointer,firstArc);">}= firstArc;(currentNode != NULL) {= currentNode->oneArc.outVertexId;(foundInArray(currentId, adjacentVertex, vertexLevel-1) != NOT_FOUND) {((currentNode != NULL) && (currentNode->oneArc.outVertexId == currentId)) {= currentNode;= currentNode->nextArc;(nodePointer, firstArc);

};

oneArc.outVertexId==currentId))=currentNode->nextArc;">}((currentNode != NULL) && (currentNode->oneArc.outVertexId == currentId))= currentNode->nextArc;

oneArc.outVertexId;(currentNode->oneArc.inVertexId!=0){=true;=NULL;((currentNode!=NULL)&&(currentNode->oneArc.outVertexId==newVertexId[counter])){>oneArc.outVertexId=counter+1;(sidePointer!=NULL){(sidePointer,firstArc);=NULL;">}= firstArc;= new int [NUM_VERTEX];= 0;(currentNode != NULL) {[counter] = currentNode->oneArc.outVer