Access elements in matrix when it is called from a function
Feb 19, 2015 at 6:19pm UTC
Write your question here.
Hi, I am having problems with this line
for (int &vecino: lista_vecinos[hormiga]). I want to go ever each element in "hormiga" column from lista_vecinos.
Here is my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <iostream>
#include<iomanip>
#include<stdio.h>
#include <fstream>
#include<stdlib.h>
#include <math.h>
#include<time.h> // libreria para el uso de time()
#include <random>
using namespace std;
int n=30; //nĂºmero de nodos o ciudades
int ** vecinos(int , int ){
int ** lista_vecinos = new int *[n];
for (int i = 0; i < n; i++) {
lista_vecinos[i] = new int [n];
for (int j = 0; j < n; j++){ lista_vecinos[i][j] = (j); }
}
return lista_vecinos;
}
int main()
{ int ** lista_vecinos = vecinos(n,n);//Call function
for (int &vecino: lista_vecinos[hormiga]) //For each element in row "hormiga" from LIsta_vecinos
{r1+=probabilidad_acumulada[hormiga][vecino]= r1;
}
}
return 0;
Thank you
Feb 19, 2015 at 7:17pm UTC
Topic archived. No new replies allowed.