public string dfs_traversal(string input, _Dictionary dictionary) { input = input.ToLower(); for (int i = 0; i < input.Length; i++) { if (input[i] < 'a' || input[i] > 'z') { continue; } if (dictionary.child['z' - input[i]] == null) { return(input); } if (i == input.Length - 1) { if (dictionary.child['z' - input[i]].occurance == 0) { return(input); } } dictionary = dictionary.child['z' - input[i]]; } return(""); }
public _Dictionary insert_node(string s) { string st = s.ToLower(); _Dictionary curruntNode = this; this.child = curruntNode.child; this.parant = curruntNode.parant; this.occurance = curruntNode.occurance; for (int i = 0; i < s.Length - 1; i++) { if (curruntNode.child['z' - st[i]] == null) { if (i == s.Length - 2) { curruntNode.child['z' - st[i]] = new _Dictionary(curruntNode, 1); } else { curruntNode.child['z' - st[i]] = new _Dictionary(curruntNode, 0); } } if (i == s.Length - 2) { curruntNode.child['z' - st[i]].occurance = 1; } curruntNode = curruntNode.child['z' - st[i]]; } return(this); }
public _Dictionary(_Dictionary parant, int occurance) { this.parant = parant; this.occurance = occurance; this.child = new _Dictionary[122]; for (int i = 0; i < 122; i++) { child[i] = null; } }
public _Dictionary() { parant = null; occurance = 0; child = new _Dictionary[122]; for (int i = 0; i < 122; i++) { child[i] = null; } }