VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time ]


[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 16:27:43 12/05/01 Wed
Author: Richard In Texas
Subject: CS515考前猜題囉

歡迎大家來猜題...
我猜Binary Search可能出現在考試。
它就是說要在一個已經排序好的Array中找data的方法,但不是從頭一個一個找,而是每次都從中間找,
例如,Array = {1,3,7,10,15,50,100} 中找 3 的演算法

Mid = (Low+High)/2 //求得中間值
if(Array[Mid] == 3)
return Mid; //找到
else if(Array[Mid] > 3) //3在前半段
{
High = Mid - 1; //範圍縮至前半段
Binary_Search; //以新的範圍,繼續做Search
}
else if(Array[Mid] < 3)
{
Low = Mid + 1; //範圍縮至後半段
Binary_Search; //以新的範圍,繼續做Search
}
if(Low == High)
程式結束;

不是粉完整,有沒人可以幫忙...Source Code更好...

[ Next Thread | Previous Thread | Next Message | Previous Message ]


Replies:


Post a message:
This forum requires an account to post.
[ Create Account ]
[ Login ]
[ Contact Forum Admin ]


Forum timezone: GMT-6
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.