Thanks for looking at this question in advance.
I am trying to order the following list of items:
Bpgvjdfj,Bvfbyfzc
Zjmvxouu,Fsmotsaa
Xocbwmnd,Fcdlnmhb
Fsmotsaa,Zexyegma
Bvfbyfzc,Qkignteu
Uysmwjdb,Wzujllbk
Fwhbryyz,Byoifnrp
Klqljfrk,Bpgvjdfj
Qkignteu,Wgqtalnh
Wgqtalnh,Coyuhnbx
Sgtgyldw,Fwhbryyz
Coyuhnbx,Zjmvxouu
Zvjxfwkx,Sgtgyldw
Czeagvnj,Uysmwjdb
Oljgjisa,Dffkuztu
Zexyegma,Zvjxfwkx
Fcdlnmhb,Klqljfrk
Wzujllbk,Oljgjisa
Byoifnrp,Czeagvnj
Into the following order:
Bpgvjdfj
Bvfbyfzc
Qkignteu
Wgqtalnh
Coyuhnbx
Zjmvxouu
Fsmotsaa
Zexyegma
Zvjxfwkx
Sgtgyldw
Fwhbryyz
Byoifnrp
Czeagvnj
Uysmwjdb
Wzujllbk
Oljgjisa
Dffkuztu
This is done by:
- Taking the first pair and putting the names into a list
- Using the second name of the pair, find the pair where it is used as the first name
- Add the second name of that pair to the list
- Repeat 2 & 3
I am populating an unordered_map with the pairs then sorting and adding each name to a list. This can be seen in the following code:
westIter = westMap.begin();
std::string westCurrent = westIter->second;
westList.push_front(westCurrent);
for(int i = 0; i < 30; i++)
{
if(westMap.find(westCurrent) != westMap.end())
{
//find pair in map where first iterator is equal to "westCurrent"
//append second iterator of pair to list
}
westIter++;
}
Note: I'm not sure if "push_front" is correct at this moment in time as I have only got the first value inserted.
My question is could someone give me some insight as to how I could go about this? As I am unsure of the best way and whether my thinking is correct. Any insight would be appreciated.