Skip to content

Instantly share code, notes, and snippets.

@nashibao
Created July 3, 2012 13:11
Show Gist options
  • Save nashibao/3039627 to your computer and use it in GitHub Desktop.
Save nashibao/3039627 to your computer and use it in GitHub Desktop.
// 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