Created
July 3, 2012 13:11
-
-
Save nashibao/3039627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Node.h | |
class Node { | |
String name; //id | |
Node** children; | |
Node* parent; | |
int numOfChildren; | |
String* nameList; | |
int layernum; | |
bool check(String* list, int lnum); | |
bool checkAbove(); | |
Node(void) {numOfChildren=0;parent=NULL;children=NULL;nameList=NULL;layernum=0;} | |
} | |
// Node.cpp | |
bool check(String* list, int lnum) { | |
nameList = list; | |
layernum = lnum; | |
if (checkAbove()) return true; | |
nameList[layernum] = name; | |
for (int i=0; i<numOfChildren;i++) { | |
if (children[i]->check(nameList,layernum+1)) return true; | |
} | |
return false; | |
} | |
bool checkAbove(int lnum) { | |
for (int i=0;i<layernum;i++) { | |
if (nameList[i]==name) return true; | |
} | |
return false; | |
} | |
// Main.cpp | |
public static void main() { | |
//… | |
String* nameList = new String[20]; | |
if(topNode->check(nameList,0)) { | |
cout <<"juhuku" << endl; | |
} | |
delete[] nameList; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment