Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Binary Search

by Jaap (Curate)
on Apr 04, 2005 at 13:10 UTC ( [id://444655]=note: print w/replies, xml ) Need Help??


in reply to Binary Search

  • Welcome to the monestary!
  • Please use <code></code> around your code
  • Please use strict; and use warnings; when you get stuck. It gives usefull error messages.
  • What is $array? Where is it initialised?
  • Are you sure you want a comma between  $low = $try+1 and next if $array...

Replies are listed 'Best First'.
Re^2: Binary Search
by dave_pl (Sexton) on Apr 04, 2005 at 13:43 UTC
    Hi all damn thanks for the fast reply!!!
    Happy to be a part of Perl Monks!
  • Hi Jaap sorry about the code tag i will
    remember it next time:)
    yes sorry about $array this should be $file2.
    just reference with the same name gives allot of problems
    so every refferance maid to @file2 should be $array
    i apologies for this but after testing so many times
    i forgot to change it. o_O
    ----------Bin Should be writen like this (SORRY)-----------
    sub bin_search { my ($array, $word) = @_; my ($low, $high) = ( 0, @$array - 1 ); while ( $low <= $high ) { # While the window is open my $try = int( ($low+$high) /2 ); # Try the middle element $low = $try+1, next if $array->[$try] lt $word; # Raise bottom $high = $try-1, next if $array->[$try] gt $word; # Lower top return $try; # We've found the word! } return; }
    THANKS AGAIN!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://444655]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-19 18:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found