getting to the root of the crash

Hi guys I am trying to implement my own version of dijkstra's shortest path algorithm,this is my second attempt at it and I would like to apoligise in advance for all the globals I will be changing them once I figure out why my program crashes,

in the compare function and more specifically in the for loop when the if condition is true this line of code or two lines of code causes a crash
firstCords[incrementCords] = first;

so I thought maybe the problem was with first so I removed first and put zero instead of first and the crash still happened

firstCords[0] = 0;

then I tried setting the firstCords[0] value manually and no crash

firstCords[0] = first;

also no crash so first isn't the problem

the problem seems to lie when I put incrementCords or even i in the [] brackets,

any idea why this is happening?

thanks


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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
  #include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream in;
int N;
int a,b,w;
int points[100][100];
int priorityQ[100][100];
int firstCords[6];
int secondCords[6];
int firstCo;
int secondCo;
int incrementCo;
int dist;
int first;
int second;

void init(){

   in >> N;
   first = 2;
   second = 3;
   firstCo = 0;
   secondCo = 0;
   incrementCo = 0;

   while(in){

       in >> a >> b >> w;
       points[a][b] = w;
   }

   for(int i = 0; i < 6; i++){

       firstCords[i] = 0;
       secondCords[i] = 0;

   }


   dist = 0;
}

void swap(int first,int second){

   int temp;


}

bool isValidPoint(int first,int second){

    if(points[first][second] != 0){

        return true;
    }
    return false;
}

void copyAndRemove(int first,int second){


}

int findShortest(int first,int second,int *ina,int *inb,int amount){

   int shortest = inb[0];

   for(int i = second+1; i < amount; i++){

      if(points[0][0] < points[0][0]){


   }
   return shortest;
}
}

void compare()
{
    int amount = 0;
    int incrementCords = 0;

    while(true)
    {
        while(true)
        {

           for(int i = 0; i < 6; i++){

             if(isValidPoint(first,second)){

                firstCords[incrementCords] = first;
               // secondCords[incrementCords] = 0;

                incrementCords++;
                amount++;

             }
             second++;
           }

          // int shortest = findShortest(first,0,firstCords,secondCords,amount);


        // here
        }

     if(first == N){

        cout << "you have reached the destination" << endl;
        break;
     }
     first++;
}
}

int main()
{

    in.open("dist.txt");
    init();
    compare();

    cout << dist << endl;
}
I even tried resetting incrementsCords to zero outside the first while loop so it didn't access an out of bounds index

but still crashes
silly me I forgot to break out of the first while loop
Topic archived. No new replies allowed.