Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include "tree.hh"
- #include <iostream>
- #include <array>
- int main(int argc, char *argv[])
- {
- //Init the database
- std::string zones[10] = {"A",
- "A",
- "B",
- "C",
- "B",
- "D",
- "D",
- "E",
- "E",
- "E"};
- std::string subZones[10] = {"A.1",
- "A.1",
- "B.1",
- "C.1",
- "B.2",
- "D.1",
- "D.2",
- "E.1",
- "E.1",
- "E.2"};
- //Prepare the strings for the categories
- std::string tempZone = "";
- std::string tempSubZone = "";
- //Prepare the tree
- tree<std::string> bodyTree;
- tree<std::string>::iterator zoneIt, subZoneIt, topIt;
- topIt = bodyTree.begin();
- //Loop the entire database
- for(int i=0; i<10; i++){
- //Grab the data
- tempZone = zones[i];
- tempSubZone = subZones[i];
- //Check if we have that zone already
- zoneIt=find(bodyTree.begin(), bodyTree.end(), tempZone);
- //If we don't have the zone, add it to the tree
- if(zoneIt==bodyTree.end()){
- bodyTree.insert(topIt, tempZone);
- std::cout << "Added new Zone: "<< tempZone << "\n";
- }
- zoneIt=find(bodyTree.begin(), bodyTree.end(), tempZone);
- //Now we have the zone for sure, we do the same with the subZone
- //Check if we have that subzone already
- tree<std::string>::iterator subZoneIt2 =find(bodyTree.begin(), bodyTree.end(), tempSubZone);
- subZoneIt=find(bodyTree.begin(zoneIt), bodyTree.end(zoneIt), tempSubZone);
- //If the subZone doesn't exist, add it to the zone
- if(subZoneIt==bodyTree.end(zoneIt)){
- bodyTree.append_child(zoneIt, tempSubZone);
- std::cout << "Added new subZone "<< tempSubZone << " --> to --> " << tempZone << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement