Social Icons

twitterfacebookgoogle plusrss feedemail

10/08/2010

資料結構-河內塔(Tower of Hanoi)

沒有留言:
ha3.gif
     小時候不知道你有沒有玩過這個遊戲,將途中的積木移至三根木釘中的其中一根上。規定在每次的移動中,只能搬移一片積木,並且在過程中必須保持金屬片由上至下是直徑由小至大的次序,也就是說不論在那一根木釘上,圓環形的積木都是直徑較小的被放在上層。
     這是個很古老的遊戲,在二下時,趙老師有叫我們自己寫過,其實這個的程式不難寫,因為有一定的規律,我們來看看這是怎麼運作的。


這其實始有規律的,如果你細心觀察的話就可以找到問題的所在,下方是河內塔的程式碼,輸入有幾個積木之後,他會自己跑並寫出解法,大家可以試試看。

資料結構與演算法-tree集合交聯集

沒有留言:
交集.png
(本文章於2010.10.08PM11:22分第二次更新)
這是二下時趙老師出給我們的一個作業,作業內容是要利用tree來完成交集、聯集的運算,我程式的寫法沒有說寫得很活,只是大概寫一下而已。

因下面加密可能會將標頭檔給去除,在自己換一下

#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>


程式碼如下:
經過作者加密,請跟作者索取密碼,並輸入相對應的密碼
wrghMTMhb8KMKwEhMCEhMCEtITExIWDCqMOaw4wZITE2MCEhMzkhw6jDrsKIwr5NBBIwLR7Cg3/Dp8KCw4jCgCExMSFoHwIyTWY9woEtw5lcITE2MCHCmCE5ITkCw7vCuMKPwqzCicKddh8wLcO2wrTDn8K1wozDuAhHa8KGwofDlcKdVkTDkC1/ITM0IWnCh8KkaW7CisO8w5jCjsOZbW/ClAEtw57Co8KzFMOOYMKEwrPlr4DlkJPntqTmpoHChcKiwrhqLcKVwofChiEzMyHDhMKZwrrCvcOAwprCk3dYw7bDvkMtw7XDq8Ofw7lReMKVTsOULMKLwpMhMzMhw7TCosK0LVI5w6/DvhtaR17Dkg/CsiExMiHClMO1OsOhLWzDsyNTbiE5IT9FS8OJXsO7wqx7I30tw6PCkS8zw7PDuXJRw4QpZBLCmcOcXcKpLcKpJcO5asKsw7/DvMKeXsO1PcK6w40Vw5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