binarytree.cs
using system;
using system.collections;
using system.collections.generic;
using system.text;
using system.text.regularexpressions;
namespace binarytree
public binarynode(object data)
private void initialchildpointer()
}public int childnum
set}
public int arraylistnum
}public object data
set}
public void addcount()
public void resetcount()
public binarynode this[int index]
}public void insertat(object info, int index)
}public void addbinarynodepointer(binarynode fnode)
public void removeat(int index)
}public delegate void visitfunc(binarynode node); //定義對樹節點訪問的委託,作為使用者傳入自己編寫的visitfunction的介面
class binarytree
}public void printexplaintion()
個子樹,最大可有個節點/n本樹用層序遍歷發開發,所以在輸入時請注意順序",objnode.arraylistnum, size);
console.writeline();
}///
/// 把字串插入到樹中,每個字元佔乙個節點
///
///
public void insertstringbychar(string insertstring)
else}}
public bool searchstringbychar(string searchstring)
else
flag = false;
}return flag;
}public void preordercreatenewtree() //先序遍歷生成樹
objstack.pop();
}break;
case "#":
return;
default:
if (parentnode.childnum < parentnode.arraylistnum)
break;
}labela: continue;
labelb: break;}}
}public void createnewtree() //使用層序遍歷建立新樹
break;
case "#":
return;
default:
if (fheadnode.childnum <= fheadnode.arraylistnum)
break;
}console.writeline();
console.writeline("請輸入資料建立其他節點");
console.writeline();
while (objqueue.count != 0)
else
goto labelb;
break;
case "#":
return;
default:
if (parentnode.childnum < parentnode.arraylistnum)
else
goto labelb;
break;
}labela: continue;
labelb: break;
}objqueue.dequeue();
public void pretransverbinarytreehelpfunc(binarynode parentnode,visitfunc action)}}
}public void printdata()
", convert.tostring(tempnode.data));}}
///
/// 搜尋父結點中是否有含有相應資料的子結點
///
///
///
///
///
private bool childsearch(binarynode parentnode,object info,int index)
private int getindexfromchar(char index)
#endregion
#region 屬性
public binarynode topnode
}#endregion }}
program.cs
using system;
using system.collections.generic;
using system.text;
using system.diagnostics;
namespace binarytree
",objbinarytree.searchstringbychar("tesa"));
/*objbinarytree.printexplaintion();
objbinarytree.preordercreatenewtree();
objbinarytree.createnewtree();
objbinarytree.printdata();
console.writeline();
dosomething objdosomething = new dosomething();
visitfunc objvisitfunc = new visitfunc(objdosomething.visitbinarynode);
objbinarytree.pretransverbinarytreehelpfunc(objbinarytree.topnode,objvisitfunc);*/
sw.stop();
console.writeline("/n程式執行時間是:", sw.elapsedmilliseconds.tostring());
console.writeline("sum=" + x.tostring());
console.readline();}}
class dosomething
", convert.tostring(node.data));
// console.writeline("^_^ !");
/* binarynode tempnode = new binarynode();
if(node.childnum != 0)
for (int i = 0; i < node.arraylistnum; i++)
",convert.tostring(tempnode.data));
}*/}}}
【from 林海聽松
快速查詢兄弟字串
如果兩個字串中的字元一樣,出現的次數也一樣,只是出現的順序不一樣,那麼他們就是兄弟字串,比如 abc 和 bca 要求 在字典中查詢兄弟字串?思路 1.現將字串進行排序 2.排序後的字串是否對應相等 1 include 2 include 3 include 4 using namespace st...
python快速查詢字串中的某個字元
import re text user lijian desktop workspace project v501 name searchcontext numlist m.start for m in re.finditer searchcontext,text print numlist比如我們...
C 版字串驗證
編輯器載入中.使用系統 使用命名 使用 命名空間bookan.others 返回true 判斷non 特殊字元 驗證字串 為空返回假 公共靜態布林isespecial 字串音節 non 數字 驗證字串 為空返回假 公共靜態布林isnumber 字串音節 字串的regex 1 9 1 0 2 的 回報...