NagpurDaMunda
In the zone
In C we normally apply binary search on array ... Is it possible to apply binary search on a text file containing sequence of words in ascending order in C language >?? if yes then how?? pls specify...
NagpurDaMunda said:In C we normally apply binary search on array ... Is it possible to apply binary search on a text file containing sequence of words in ascending order in C language >?? if yes then how?? pls specify...
NagpurDaMunda said:i m in school...in 3rd..
1. I suppose the words in the file r separated by spaces or commas or ny other delimiter
IF words r separated by a space then ur work will be a lot easier
2.Create an object of the ifstream class(fin for me)
3. now use this object to read all the words into a Double-Dimension array ,hence in this DD array each element is a word
4. Now use strcmp() to compare words n do the normal binary search mechanism
File words.txt containing the words said:abc def ghi jkl mn op qr st unwz yz
PHP Code said:<?php
$words = file_get_contents("file_get_contents ");
$words = explode(" " , $words);
//Now the variable $Words is a Double-Dimension array with each element as a word
/* now you can do your binary search on this array */
?>
C++ Code said:#include<fstream>
int main()
{
/*Supposing the file has 10 words , if we didn't know the exact number of words then the program would be MUCH lengthier
also we are supposing that each word is not larger than 10 characters else then too we would hv to add a lot of code to
determine the length of the largest word , also a loop would be needed to determine the number of words then we would
dynamically allocate the size of the array using new() function*/
char words[10][10];
ifstream fin("words.txt");
for ( int i = 0 ; i < 10 ; i++)
fin >> words
// now each element of the array words is a word , hence we can perform our binary search on this
// array using strcmp() function
return 0;
}