Click here to Skip to main content
15,906,645 members
Home / Discussions / Algorithms
   

Algorithms

 
QuestionWeather Prediction using minimal data Pin
nootanghimire16-May-13 23:06
professionalnootanghimire16-May-13 23:06 
AnswerRe: Weather Prediction using minimal data Pin
dusty_dex16-May-13 23:58
dusty_dex16-May-13 23:58 
GeneralRe: Weather Prediction using minimal data Pin
nootanghimire17-May-13 23:50
professionalnootanghimire17-May-13 23:50 
GeneralRe: Weather Prediction using minimal data Pin
dusty_dex18-May-13 2:49
dusty_dex18-May-13 2:49 
GeneralRe: Weather Prediction using minimal data Pin
Dave Kreskowiak29-May-13 18:40
mveDave Kreskowiak29-May-13 18:40 
AnswerRe: Weather Prediction using minimal data Pin
Richard MacCutchan18-May-13 5:42
mveRichard MacCutchan18-May-13 5:42 
AnswerRe: Weather Prediction using minimal data Pin
Joezer BH16-Jun-13 23:29
professionalJoezer BH16-Jun-13 23:29 
QuestionBest autorrelation function Pin
Russell'7-May-13 0:36
Russell'7-May-13 0:36 
QuestionPattern matching in trees, lists and strings alike Pin
bjongejan11-Apr-13 9:19
bjongejan11-Apr-13 9:19 
AnswerRe: Pattern matching in trees, lists and strings alike Pin
dusty_dex11-Apr-13 11:44
dusty_dex11-Apr-13 11:44 
GeneralRe: Pattern matching in trees, lists and strings alike Pin
bjongejan11-Apr-13 22:49
bjongejan11-Apr-13 22:49 
GeneralRe: Pattern matching in trees, lists and strings alike Pin
dusty_dex11-Apr-13 23:04
dusty_dex11-Apr-13 23:04 
GeneralRe: Pattern matching in trees, lists and strings alike Pin
bjongejan12-Apr-13 9:25
bjongejan12-Apr-13 9:25 
GeneralRe: Pattern matching in trees, lists and strings alike Pin
Kosta Cherry5-Jun-13 20:04
Kosta Cherry5-Jun-13 20:04 
You can do anything in C++. your example can be done as this:

C++
std::string mystdarr[][2] = {{"Abel","Hirst"},{"Benjamin","Foster"},{"Letty","Johnson"},{"George","Hanson"},{"Chris","Johnson"},{"Priscilla","Stein"}, {"",""}};
int arrsize = sizeof(mystdarr)/sizeof(mystdarr[0]);
for (auto it=0; it < arrsize - 1; ++it) {
   auto itFound = std::find_if(&mystdarr[it+1], &mystdarr[arrsize-1], [&](const std::string (&cmp)[2]) { return !cmp[1].compare(mystdarr[it][1]); });
   if (itFound != (std::string (*)[2])(mystdarr[arrsize-1]))
      std::cout << mystdarr[it][0].c_str() << " and " << (*itFound)[0].c_str() << " have the same family name (" << (*itFound)[1].c_str() << ")\n";
}



Or, if you'd like less cryptic code (it's cryptic because built-in arrays in C/C++ are by no means flexible), you can do this:
C++
struct SS
{
   std::string firstName;
   std::string lastName;
   SS(const std::string& fname, const std::string& lname) : firstName(fname), lastName(lname) {};
};
std::vector<SS> myarr;
myarr.push_back(SS("Abel", "Hirst"));
myarr.push_back(SS("Benjamin", "Foster"));
myarr.push_back(SS("Letty", "Johnson"));
myarr.push_back(SS("George", "Hanson"));
myarr.push_back(SS("Chris", "Johnson"));
myarr.push_back(SS("Priscilla", "Stein"));
for (auto it=myarr.begin(); it!=myarr.end(); ++it)
{
   auto itFound = std::find_if(it + 1, myarr.end(), [&](const SS& cmp) {return !cmp.lastName.compare(it->lastName);});
   if (itFound != myarr.end())
      std::cout << it->firstName.c_str() << " and " << itFound->firstName.c_str() << " have the same family name (" << it->lastName.c_str() << ")\n";
}

QuestionAlgorithm Pin
Member 99636023-Apr-13 15:11
Member 99636023-Apr-13 15:11 
AnswerRe: Algorithm Pin
BupeChombaDerrick7-Apr-13 23:39
BupeChombaDerrick7-Apr-13 23:39 
QuestionAlignment and rectification of polylines Pin
Chesnokov Yuriy1-Apr-13 8:09
professionalChesnokov Yuriy1-Apr-13 8:09 
AnswerRe: Alignment and rectification of polylines Pin
Kenneth Haugland2-Apr-13 23:31
mvaKenneth Haugland2-Apr-13 23:31 
AnswerRe: Alignment and rectification of polylines Pin
Lutosław4-Jun-13 12:57
Lutosław4-Jun-13 12:57 
QuestionConsider a complete binary tree with an odd number of nodes. Let n be the number of internal nodes (non-leaves) in the tree. Define the internal path length, I, as the sum, taken over all the internal nodes of the tree, of the depth of each node. Lik Pin
amistry_petlad28-Mar-13 7:08
amistry_petlad28-Mar-13 7:08 
AnswerRe: Consider a complete binary tree with an odd number of nodes. Let n be the number of internal nodes (non-leaves) in the tree. Define the internal path length, I, as the sum, taken over all the internal nodes of the tree, of the depth of each node. Pin
R. Giskard Reventlov28-Mar-13 7:24
R. Giskard Reventlov28-Mar-13 7:24 
AnswerRe: Consider a complete binary tree with an odd number of nodes. Let n be the number of internal nodes (non-leaves) in the tree. Define the internal path length, I, as the sum, taken over all the internal nodes of the tree, of the depth of each node. Pin
Richard MacCutchan28-Mar-13 7:25
mveRichard MacCutchan28-Mar-13 7:25 
GeneralRe: Consider a complete binary tree with an odd number of nodes. Let n be the number of internal nodes (non-leaves) in the tree. Define the internal path length, I, as the sum, taken over all the internal nodes of the tree, of the depth of each node. Pin
amistry_petlad28-Mar-13 7:51
amistry_petlad28-Mar-13 7:51 
GeneralRe: Consider a complete binary tree with an odd number of nodes. Let n be the number of internal nodes (non-leaves) in the tree. Define the internal path length, I, as the sum, taken over all the internal nodes of the tree, of the depth of each node. Pin
Richard MacCutchan28-Mar-13 7:58
mveRichard MacCutchan28-Mar-13 7:58 
AnswerRe: Consider a complete binary tree with an odd number of nodes. Let n be the number of internal nodes (non-leaves) in the tree. Define the internal path length, I, as the sum, taken over all the internal nodes of the tree, of the depth of each node. Pin
Lutosław4-Jun-13 13:06
Lutosław4-Jun-13 13:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.