Created
September 15, 2013 15:48
-
-
Save baobao/1dcd3c63209b725339c8 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
function tree(str:String):void | |
{ | |
var trees:Array = str.split(","); | |
var retisters:Array = []; | |
var map:Object = {}; | |
for (var i:int = 0; i < trees.length; i++) | |
{ | |
var t:String = trees[i]; | |
var temp:Array = t.split("/"); | |
if (i == 0) | |
{ | |
// 初回はそのまま登録 | |
retisters[i] = temp; | |
} | |
else | |
{ | |
retisters = checkArray(retisters, temp, i); | |
} | |
} | |
for (i = 0; i < retisters.length; i++) | |
{ | |
trace(retisters[i]); | |
} | |
} | |
function checkArray(registers:Array, nexts:Array, index:int):Array | |
{ | |
trace("nexts::" + nexts, index); | |
var checkArray:Array = registers.concat(); | |
for (var i:int = 0; i < checkArray.length; i++) | |
{ | |
var pattern:Array = checkArray[i]; | |
if (pattern == null) return registers; | |
for (var j:int = 0; j < pattern.length; j++) | |
{ | |
var key:String = pattern[j]; | |
if (nexts[j] == null) | |
{ | |
trace("break::" ,i, j); | |
return registers; | |
} | |
else | |
{ | |
if (key != nexts[j]) | |
{ | |
// 登録されていなかったら | |
if (registers[index] == null) | |
{ | |
registers[index] = [nexts[j]]; | |
} | |
else | |
{ | |
registers[index].push(nexts[j]); | |
} | |
} | |
else | |
{ | |
// 登録されていたら | |
if (registers[index] == null) | |
{ | |
registers[index] = ["|__|"]; | |
} | |
else | |
{ | |
registers[index].push("|__|"); | |
} | |
} | |
} | |
} | |
} | |
return registers; | |
} | |
tree("a/b/c,a/b/d,a/h,a/h/g"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment