Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Fred
Finding a path between nodes -- C++?
finding path between structs, struct is read in as argument. Flights look like
BOS ORD 1002120.200
XYZ ABC 2023.2323
ABC BOS 2300.22
two 3 letter strings then a double
my struct looks like this:
//struct for holding flights
struct flight{
//string departure
string dep;
//string destination
string dest;
//double for holding price
double price;
} fl;
my code to find a path looks like this:
bool findPath(string dep, string dest, vector<flight> &RAND_FLIGHTS){
cout << "Finding Path..." << endl;
//value for return
bool retbool = false;
//cycle thru vector
for(int i=0; i<RAND_FLIGHTS.size(); i++){
//if case... a single flight is the correct answer
if((RAND_FLIGHTS[i].dep == dep) && (RAND_FLIGHTS[i].dest == dest)){
retbool = true;
}
//else if case, indirect path
if((RAND_FLIGHTS[i].dep == dep) && (RAND_FLIGHTS[i].dest != dest)){
dep = RAND_FLIGHTS[i].dest;
RAND_FLIGHTS.erase(RAND_FLIGHTS.begin()+i);
findPath(dep, dest, RAND_FLIGHTS);
}
//else -- no matches for departure
else{ //if((RAND_FLIGHTS[i].dep == dep) && (RAND_FLIGHTS[i].dest != dest)){
//retbool = false;
cout << "else case" << endl;
}
}
return retbool;
}
trying to make it so it returns true if there is a path or false if there is not.
Thanks in advance for any help!
1 AnswerProgramming & Design10 years agoC++ Question, Binary Searching!?
here is my code, i am trying to binary search a vector to see if it is finding the right stuff.
i am using std::sort in main, so it is sorted
here is my code: it is currently throwing a segfault or not running at all.. but it compiles fine
//boolean to test incoming words if they are, indeed a stop_word
bool isStopWord(string word, vector<string> &STOP_WORDS){
//sort( STOP_WORDS.begin(), STOP_WORDS.end() );
//boolean for return
bool retbool = false;
//binary search this badboy
int low = 0;
int high = STOP_WORDS.size();
while(low<=high){
int middle = low + ((high-low)/2);
if(word < STOP_WORDS[middle]){
high = middle-1;
}
else if(STOP_WORDS[middle] < word){
low=middle+1;
}
else{
retbool = true;
}
}
return retbool;
}
1 AnswerProgramming & Design10 years agoC++ Question, tailoring a string!?
here is my code, trying to make it so that it will edit a string like 'P0oP'
so that it'll be turned into
'pop'
it's throwing me a core dump right now.
string fixString(string s){
for(int i=0; i<s.length(); i++){
char c = s[i];
if(c>='a' && c<='z'){
s[i] = tolower(s[i]);
}
else{
s.erase(i,1);
}
}
}
thanks in advance!
2 AnswersProgramming & Design10 years agoIs there any way to get Starcraft installed without Mac Classic?
I have OS X and not OS 9 and can't get it installed, any ideas or ways around this problem?
2 AnswersVideo & Online Games1 decade agoAre there any known online RPGs coming out for Wii in the near future?
Yea, kinda hoping for an MMORPG to come out for the Wii. Anyone have any ideas? Any RPG that's online will do though :D
2 AnswersVideo & Online Games1 decade ago