C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 1st, 2004, 02:04 PM
deadlock75 deadlock75 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 5 deadlock75 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question whats next

Right now I am completely stuck on this the program works fine but I do not know how to input data that should be on a text file. And also test the function using the sorted arrays like quicksort, both random array of integers and the posted data.

#include <stdio.h>
#define DESIRED_VAL 44
#define ARR_SIZE 50
int binsrch (int *arr, int lb, int up);
main()
{
int arr [ARR_SIZE], i,j, lower, upper, index;
for (i=0;i<ARR_SIZE; i=i+1)
arr[i]= 2*i;
printf ("Desired Value = %d\n", DESIRED_VAL);
lower = 0;
upper = ARR_SIZE-1;
index = binsrch (arr, lower, upper);
if (index > 0)
printf ("the number %d was found at index %d\n", DESIRED_VAL, index);
else
printf ("the number %d was not found\n", DESIRED_VAL);
}

int binsrch (int *arr, int lb, int up)
{
int mid;
int index;
mid = (up+lb)/2;
if (lb>up)
return (-1);
printf ("looking in position %d\n", mid);
if (arr[mid]==DESIRED_VAL)
return (mid);
if (arr[mid]<DESIRED_VAL)
{
return (binsrch (arr, mid+1, up));
}
else
{
index = binsrch(arr, lb, mid-1);
return (index);
}
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > whats next


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT