olifegroup wrote:
> i am having a problem with developing a c++ code using a linked list
> implementation. The aim of the project is to make abook index.
>
> the linked list contains, list that is dedicated for storing words
> and each word node has its own another list called page, which
> stores the page where the word is found in the file and each page
> has its own node. If a word is repeated the only thing that is
> perfomed is appending the page to that words page list and if the
> page already exists it will discard it.
>
> the book indexing program contains the following functions
>
>> read a list of words from a file "book.txt" and appends the read
> word to the inked list in sorted manner.
>
>> search from the list of words that are indexed
>> destroy the whole list(page and word)
>> delete a specific word
>> if possiblie the line number can be also added
>
> please, please i appriciate ur kind support. Ind i am fully
> confident that i will get smoe source codes from u. thanks...
If this is homework, you're going to have to provide source code.
Otherwise, I'd consider using something other than a linked list. A
hash and a used words array/block are going to be much more efficient
than maintaining a sorted linked list. Pseudocode:
while (...word exists...)
{
// Read word.
Data = WordMap.Find(CurrWord);
if (Data) *Data += PageNum;
else
{
WordMap.Insert(CurrWord, Block<size_t>(PageNum));
WordList += CurrWord;
}
}
WordList.Sort();
y = WordList.GetSize();
for (x = 0; x < y; x++)
{
CurrWord = WordList[x];
Data = WordMap.Find(CurrWord);
if (Data)
{
...print CurrWord...
y2 = Data->GetSize();
for (x2 = 0; x2 < y2; x2++) ...print page number...
}
}
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/