I'm creating a program that will search for a word in a text file using binary search algorithm. I already read about binary search. Anyway, assuming the text file that needs to be searched is "abc.txt" that contains: ABC DEF Rudolf Andrew James Robert Ryan Six Seven Eight Ten Twenty Four
I run the program and entered the filename and it can only found some words like "Ryan" and "Rudolf". The program can't find other words that exist in the text file like Andrew. So I tried to add some codes so that I will see how the program finds the words (The line of codes with asterisk comments on it) and added a delay of 1sec. I need to find all the words that exist in the text file. Please help me
I'm pretty sure binary searches will only work on sorted lists. The words in your text file would need to be sorted first. You'd probably get screwy results otherwise.
As for other examples using arrays, why not just read the lines from your text file into an array (or, better yet, a vector).
how will I 'sort' the word of the text file?
Anyway that abc.txt is just a sample that's why it only contains 13 words.
I will use the program to search a word in a text file with 100, 1000, 10000, 100000, and 1000000 records and each record contains 256 characters. :)))
I already finished coding a linear search algorithm and I am creating another search algorithm (the binary search algorithm which I'm doing right now)