C/C++

Не работает код на c++

 #include    
#include
#include

using namespace std;

const int maxV = 1000;

// Функция для перевода массива смежности в список смежности
void convertToAdjList(int G[][maxV], int V, vector adjList[]) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (G[i][j] != 0) {
adjList[i].push_back(j);
}
}
}
}

int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int a;
do {
printf("Введите операцию:\n");
printf_s("0:Алгоритм Флойда\n");
scanf_s("%d", &a);
switch (a)
{
case 0:
setlocale(LC_ALL, "Rus");
cout > n;
int GR[maxV][maxV];
vector adjList[maxV];

cout
Kolia Dzadzua
Kolia Dzadzua
67
Стек программы не резиновый. Обычно ограничен 1 мегабайтом.
int GR[1000][1000] - занимает 4 мегабайта стека из за того что он статический.
то же самое относится к vector adjList[1000] - конечно это гораздо меньше, но все же около 40 килобайт стека. Смело засовывайте все в один вектор.

 #include     
#include
#include

using namespace std;


// Функция для перевода массива смежности в список смежности
void convertToAdjList(const vector&G, int V, vector& adjList) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (G[i][j] != 0) {
adjList[i].push_back(j);
}
}
}
}

int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int a;
vector GR;
vector adjList;
do {
cout a;
switch (a)
{
case 0:
setlocale(LC_ALL, "Rus");
cout > n;
GR = vector(n,vector(n));
adjList = vector (n);
cout
Олег Щербаков
Олег Щербаков
51 416
Лучший ответ
 #include     
#include
#include
using namespace std;

const int maxV = 1000;

// Функция для перевода массива смежности в список смежности
void convertToAdjList(int G[][maxV], int V, vector adjList[]) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (G[i][j] != 0) {
adjList[i].push_back(j);
}
}
}
}

int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int a;
do {
printf("Введите операцию:\n");
printf("0:Алгоритм Флойда\n");
scanf("%d", &a);
switch (a)
{
case 0:
setlocale(LC_ALL, "Rus");
cout > n;
int GR[maxV][maxV];
vector adjList[maxV];

cout
Kolia Dzadzua Не знаю, в чем проблема, но C:\Users\user\source\repos\3 задача\x64\Debug\3 задача.exe (процесс 5860) завершил работу с кодом -1073741571.
Нажмите любую клавишу, чтобы закрыть это окно:
Эркин Азимов -1073741571 0xC00000FD STATUS_STACK_OVERFLOW