Current location: Hot Scripts Forums » Programming Languages » C/C++ » Binary Search How to have just number argument


Binary Search How to have just number argument

Reply
  #1 (permalink)  
Old 05-27-09, 12:46 PM
Hamed Hamed is offline
Wannabe Coder
 
Join Date: Jan 2007
Posts: 187
Thanks: 2
Thanked 0 Times in 0 Posts
Binary Search How to have just number argument

I know this code for binary search
Code:
int search(int a[], int key, int low, int high) {
    if (high < low) {
        return NOT_FOUND; 
    }
    int mid = (low + high) / 2;
    if (key>a[mid]) {
        return searchName(a, key,low, mid-1);
    } else if (key<a[mid]) {
        return searchName(a, key,mid+1, high);
    } else {
        return EXIT_SUCCESS; 
    }
    return ERROR_SEARCH;
}
Now I want to make recursive one which just need
int search(char *dict, char *name,int length,int compChars)
and length is number element in array.
please help me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-28-09, 02:46 PM
Hamed Hamed is offline
Wannabe Coder
 
Join Date: Jan 2007
Posts: 187
Thanks: 2
Thanked 0 Times in 0 Posts
[PHP]
PHP Code:

int bs(int array[],int n,int key)

{
    
int mid,low=0,high=(n-1);
    
mid=n/2;
    
printf("high:%d--low:%d\n",high,low);
    if(array[
mid] == key)
    {
        return(
mid);
    }
    if(array[
mid]>key)
    { 
         
printf("mid>key\t");printf("array[mid]=%d--mid=%d\n",array[mid],mid);
        return(
bs(&(array[0]),mid,key));
    }
    if(array[
mid]<key)
    {
                      
printf("mid<key\n");printf("array[mid]=%d--mid=%d\n",array[mid],mid);
        return(
bs(&(array[mid+1]),mid,key));
    }
    if(
high low)
    {
         return(-
1);
    }
    else{
         return(-
1);
    }

This one work for all exit element but there is not condition to stop when element now exit!??
Please test it and help.I really need it before next midnight.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-24-09, 08:07 AM
mkcitizen mkcitizen is offline
New Member
 
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for this coding if any doubts ask me i am here to help u friends
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Search () & regex exact number. Snowball JavaScript 2 03-03-08 11:06 AM
Guaranteed number 1 ranking on a very popular search engine and It's free, no cost. grgx General Advertisements 0 02-16-05 08:21 AM
SEO Expert Available nakulgoyal Job Offers & Assistance 2 08-14-04 01:38 PM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 09:58 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.