Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-16-2009, 10:26 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
binary_search

Should be self explaining...

PHP Code:
temp.array = {12345678910};
binary_search(array, 2); // returns true
binary_search(array, 11); // returns false

function binary_search(array, value) {
  
temp.volume = array.size();
  
temp.middleElement int(volume/2);
  
temp.start = (array[middleElement] < value?middleElement:0);
  
temp.end = (start==0?middleElement+1:volume);
  for (
startendi++) {
    if (array[
i] == value) {
      return 
true;
    }
  }
  return 
false;

Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:28 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.