Тема: Проходження графу в ширину.
Компілятор не видає помилку... Але й програма не виконується. Скоріш за все написав якусь дурню. Подивіться будь ласка.
#include <conio.h>
#include <iostream>
#include <string>
using namespace std;
struct station {
    station* commonst;
    string namest;
    int way;
};
struct list {
    station* station;
    list* next;
};
void listt(list**first,station *roll) {
    list* fsroll = *first;
    if (fsroll->next == nullptr) {
        fsroll->next = new list;
        fsroll = fsroll->next;
        fsroll->station = roll;
        fsroll->next = nullptr;
    }
    else {
        while (fsroll->next!= nullptr) {
            fsroll = fsroll->next;
        }
        fsroll->next = new list;
        fsroll = fsroll->next;
        fsroll->station = roll;
        fsroll->next = nullptr;
    }
    
}
void mainnlist(station** main, int num,list **mainlistst) {
    if ((*mainlistst) == nullptr) {
        cout << "Введіть назву станції із якої Ви хочете обійти лінії метро в ширину: ";
        string name;
        cin >> name;
        for (int i = 0; i < num; i++) {
            if ((*main)->namest == name) {
                (*mainlistst) = new list;
                (*mainlistst)->station =(*main);
                (*mainlistst)->next = nullptr;
            }
        }
        
    }
    else {
        if ((*mainlistst) != nullptr) {
            list* filist = (*mainlistst);
            while (filist) {
                station* save = filist->station;
                while (save) {
                    listt(&filist, save);
                    save = save->commonst;
                }
                filist = filist->next;
            }
            
        }
    }
}
void printlist(list* print) {
    list* nm = print;
    while (nm) {
        cout << nm->station->namest;
        nm = nm->next;
    }
}
void print(station** mainst,int num) {
    for (int i = 0; i < num; i++) {
        cout << "Назва " << i + 1 << "-ої станції метро: " << mainst[i]->namest << endl;
    }
}
void cincommonst(station*** mainst, int num) {
    for (int i = 0; i < num; i++) {
        cout << "Введіть к-сть суміжніх пересадок для станції " << (*mainst)[i]->namest << ": ";
        int numm;
        cin >> numm;
        station* newst = (*mainst)[i];
        for (int q = 0; q < numm; q++) {
            cout << "Введіть назву " << q + 1 << "-ої пересадки із станції: " << (*mainst)[i]->namest << ": ";
            if (newst->commonst == nullptr) {
                (newst)->commonst = new station;
                (newst) = (newst)->commonst;
                cin >> (newst)->namest;
                cout << "Введіть довжину  " << q + 1 << "-ої пересадки із станції: " << (*mainst)[i]->namest << ": ";
                cin >> (newst)->way;
                newst->commonst = nullptr;
            }
            else {
                while (newst->commonst) {
                    newst = newst->commonst;
                }
                (newst)->commonst = new station;
                (newst) = (newst)->commonst;
                cin >> (newst)->namest;
                cout << "Введіть довжину  " << q + 1 << "-ої пересадки із станції: " << (*mainst)[i]->namest << ": ";
                cin >> (newst)->way;
                newst->commonst = nullptr;
            }
        }
        cout << endl;
    }
}
void printcommonst(station** mainst, int num) {
    for (int i = 0; i < num; i++) {
        station* printst = mainst[i];
        while (printst->commonst) {
            printst = printst->commonst;
            cout << "Із станції " << mainst[i]->namest << " можна патрапити у станцію " << printst->namest << " із довжиною шляху: " << printst->way << " км." << endl;
        
        }
        cout << endl;
    }
}
int main(void) {
    setlocale(LC_ALL, "Ukr");
    station** mainst = nullptr;
    list* mainlist = nullptr;
    list* list = nullptr;
    int num;
    cout << "Введіть к-сть станцій: ";
    cin >> num;
    mainst = new station * [num];
    for (int i = 0; i < num; i++) {
        cout << "Введіть назву " << i + 1 << "-ої станції метро: ";
        mainst[i] = new station;
        string name;
        cin >> name;
        mainst[i]->namest = name;
        mainst[i]->commonst = nullptr;
        mainst[i]->way = NULL;
    }
    print(mainst, num);
    cincommonst(&mainst, num);
    printcommonst(mainst, num);
    mainnlist(mainst, num, &mainlist);
    mainnlist(mainst, num, &mainlist);
    printlist(mainlist);
    _getch();
    return 0;
}