Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Community Calendar Today's Posts Search
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > Science and Art > Tech Help

 
 
Thread Tools Display Modes

 
Question Whats next
Reply
Posted 2004-12-01, 02:07 PM
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);
}
}
Old
Profile PM WWW Search
deadlock75 is neither ape nor machine; has so far settled for the in-betweendeadlock75 is neither ape nor machine; has so far settled for the in-between
 
deadlock75
 
 

Bookmarks

« Previous Thread | Next Thread »

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

Posting Rules [Forum 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 -6. The time now is 04:23 AM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.