Click here to Skip to main content
15,881,715 members
Home / Discussions / Algorithms
   

Algorithms

 
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 
QuestionThe degree of a node in a tree is the number of children the node has. If a tree has n1 nodes of degree 1, n2 nodes of degree 2, ..., nm nodes of degree m, compute the number of leaves in the tree in terms of n1, n2, . . . , nm. Pin
amistry_petlad28-Mar-13 7:04
amistry_petlad28-Mar-13 7:04 
NewsCaltech's FREE online Machine Learning course -- LAST CHANCE Pin
Matt T Heffron27-Mar-13 11:53
professionalMatt T Heffron27-Mar-13 11:53 
NewsNew computer vision algorithms, check out the videos Pin
BupeChombaDerrick20-Feb-13 20:33
BupeChombaDerrick20-Feb-13 20:33 
GeneralRe: New computer vision algorithms, check out the videos Pin
Simon_Whale1-Mar-13 0:13
Simon_Whale1-Mar-13 0:13 
GeneralRe: New computer vision algorithms, check out the videos Pin
BupeChombaDerrick1-Mar-13 23:24
BupeChombaDerrick1-Mar-13 23:24 
QuestionComplexity and Routing Problems Pin
brkonja18-Feb-13 13:10
brkonja18-Feb-13 13:10 

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.