i run this program and it gives the runtime error
" Runtime error: exit code is -1073741819 ".
can someone plz tell me why tis error occurs and how to rectify it?
the program is finding the word ladder (length of the shortest chain to reach the target word) . i.e Given a dictionary, and two words ‘start’ and ‘target’ (both of same length). Find length of the smallest chain from ‘start’ to ‘target’ if it exists, such that adjacent words in the chain only differ by one character and each word in the chain is a valid word i.e., it exists in the dictionary. It may be assumed that the ‘target’ word exists in dictionary and length of all dictionary words is same.
#include<bits/stdc++.h>
using namespace std;
string dic[] = {"POON", "PLEE", "SAME", "POIE", "PLEA", "PLIE", "POIN"};
int n = sizeof(dic)/sizeof(dic[0]);
set<string> graph;
struct word
{
string s;
int d;
};
bool isAdj(string &s , string &t)
{
int count = 0;
for(int i=0; i<s.length() && i<t.length(); i++)
if(s[i] != t[i])
count++;
return (count == 1);
}
int shortestPath(string s , string d)
{
queue<word> que;
word source = {s , 0};
que.push(source);
word cur;
//string t = "PLEA";
while(!que.empty())
{
cur = que.front();
if(cur.s == d)
break;
for(string t : graph)
{
if(isAdj(cur.s , t))
{
word temp = {t, cur.d + 1};
que.push(temp);
graph.erase(t);
}
}
que.pop();
}
if(cur.s == d)
return cur.d;
return 0;
}
main()
{
for(int i=0; i<n; i++)
graph.insert(dic[i]);
cout<<" "<<shortestPath("TOON" , "PLEA") ;
}
the question link is here http://www.geeksforgeeks.org/word-ladder-length-of-shortest-chain-to-reach-a-target-word/
thanks in advance.