我一直負責製作一個按標題,流派,年份,等級,主演等搜索400多部電影(鏈接在一起使用鏈接列表)的程序。搜索鏈接列表,不同的數據類型
雖然有一個問題,但我們只允許一個搜索功能來通過鏈表進行搜索。此外,該搜索功能中,我們只允許一個while循環,這是我在我的情況下,假設將是這樣的......
while (moviePtr != NULL)
顯然他們會有很多不同的情況下,如果一個演員的搜索,或者類型搜索。在演員,流派,評級,年份,子類型和輔助角色的情況下,應該輸出找到的每一個實例。 (例如,如果Kevin Bacon在x-men和筆記本上,它不僅應該輸出其中的一個(輸出文件而不是屏幕))。
我發現自己完全被這些限制給絆倒了。 我的搜索功能將如何處理不同的數據類型? (年份和評分必須聲明爲整數)。它將如何知道我在尋找什麼?如果我正在尋找演員,我不希望它搜索標題。
任何有關如何開始和開始的建議非常感謝。
編輯: 嗨所有想到的ID更新你們什麼我做了。我有3種不同的搜索功能。一個用於數值(年份和評分),一個用於流派和演員,最後一個用於標題。
這是他們三人的代碼。 首先標題搜索。
void TitleSearched(MovieNode*head,
string titleSearched,
ofstream& outFile)
{
MovieNode* moviePtr;
bool found;
moviePtr = head;
found = false;
while (moviePtr !=NULL & !found)
{
if (moviePtr-> title == titleSearched)
{
found = true;
}
else
{
moviePtr = moviePtr -> next;
}
}
if (found)
{
cout << endl << titleSearched << " has been found!\n";
TitleOutput (moviePtr,outFile);
}
else
{
cout << endl << titleSearched << " was not found.\n";
}
}
now the year/rating search。
int NumSearched(MovieNode* head, int numSearched)
{
int instances;
MovieNode* moviePtr;
ofstream outFile;
moviePtr = head;
instances = 0;
while (moviePtr !=NULL)
{
if (moviePtr-> year == numSearched)
{
instances = instances +1;
NumOutList(moviePtr,outFile,"year",numSearched,instances);
moviePtr = moviePtr -> next;
}
else if (moviePtr->rating == numSearched)
{
instances = instances +1;
NumOutList(moviePtr,outFile,"rating",numSearched,instances);
moviePtr = moviePtr -> next;
}
else
{
moviePtr = moviePtr ->next;
}
}
return instances;
}
最後流派/演員搜索。
int ItemSearch (MovieNode* head,string itemSearched, ofstream& outFile)
{
int instances;
MovieNode* moviePtr;
moviePtr = head;
instances = 0;
while (moviePtr !=NULL)
{
if (moviePtr-> genre == itemSearched || moviePtr ->subGenre == itemSearched)
{
instances = instances +1;
OutList(moviePtr,outFile,"Genre",itemSearched,instances);
moviePtr = moviePtr -> next;
}
else if (moviePtr->leadActor == itemSearched || moviePtr->supportActor == itemSearched)
{
instances = instances +1;
OutList(moviePtr,outFile,"Actor",itemSearched,instances);
moviePtr = moviePtr -> next;
}
else
{
moviePtr = moviePtr ->next;
}
}
return instances;
}
我想提醒你們,我的任務是什麼。 1.結合這三個搜索功能爲一體 2.具有隻有一個while循環搜索 3.在任何給定的功能只有一個返回(但是,ID假設這將是一個void函數結合時)
我主要問題我貝雷夫是我的整理和絃樂。我不能將評級或年份聲明爲字符串。只是在整體梳理所有三個代碼的格式是給我一個頭痛
您的搜索條件是否指定您要查找的內容「凱文培根」+「演員」還是你應該猜猜他們在找什麼? – Kiril 2012-04-20 19:49:18
用戶使用枚舉類型從菜單中選擇想要搜索的內容,例如,類型爲0,退出,1-標題搜索,2-搜索我的評分,3-按年搜索,4-按演員搜索, etc – 2012-04-20 20:21:13
增加了一個新的編輯。多謝你們! – 2012-04-23 01:45:43