#include #include using namespace std; struct node { int from; int too; int dist; node* next; }; struct macMN { int** matrix; int size; }; void AddNodeToLN(node*& H, int too1, int distance) { node* p = new node; p->too = too1; p->dist = distance; p->next = H; H = p; } void DelNode(node*& H) { node* p = H; H = H->next; delete p; } void showLE(node* Head) { if (Head != NULL) { node* HE = Head; cout << "LE ->dist/from/too -> "; while (HE != NULL) { cout << HE->dist << "/" << HE->from << "/" << HE->too << "/" << "->"; HE = HE->next; } cout << "NULL" << endl; } cout << endl; } macMN GenerateMN(string FileName) { macMN MN; fstream czytaj; czytaj.open(FileName); int n; czytaj >> n; MN.matrix = new int* [n]; for (int i = 0; i < n; i++) MN.matrix[i] = new int[n]; MN.size = n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) czytaj >> MN.matrix[i][j]; czytaj.close(); return MN; } node** GenerateLN(string FileName) { node** LN; fstream czytaj; int value = 0; czytaj.open(FileName); int n; czytaj >> n; LN = new node * [n]; for (int i = 0; i < n; i++) LN[i] = NULL; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { czytaj >> value; if (value > 0) AddNodeToLN(LN[i], j, value); } } czytaj.close(); cout << endl; return LN; } void showMN(macMN MN) { for (int i = 0; i < MN.size; i++) { for (int j = 0; j < MN.size; j++) { cout << MN.matrix[i][j] << " "; } cout << endl; } } void showLN(node** LN, int size) { node* p = NULL; for (int i = 0; i < size; i++) { p = LN[i]; cout << "H[" << i << "]="; while (p != NULL) { cout << p->too << "/" << p->dist << "->"; p = p->next; } cout << "NULL" << endl; } cout << endl; } int main() { node** LN = NULL; node* LE = NULL; macMN MN; int n = 0; // graf size fstream czytaj; string FileName = "grafy.txt"; czytaj.open(FileName); czytaj >> n; czytaj.close(); MN = GenerateMN(FileName); //Matrix of neighbourhood showMN(MN); LN = GenerateLN(FileName);//List of neighbourhood showLN(LN, n); system("pause"); return 0; }