#include <iostream>
#include <strstream>
#include <string>
using namespace std;
class TSpisok
{
private:
std::string Word;
TSpisok *Next;
TSpisok* First;
TSpisok* Current;
int Count;
public:
TSpisok()
{
First = NULL;
Current = NULL;
Count = 0;
}
void Add(std::string vWord);
std::string GetWord(void)
{
return Word;
}
TSpisok* NextPosition(void)
{
return Next;
}
TSpisok* GetFirst(void)
{
return First;
}
};
void TSpisok::Add(std::string vWord)
{
TSpisok *Temp = new TSpisok;
Temp->Word = vWord;
Temp->Next = NULL;
if (!First)
{
First = Temp;
}
else
{
Current->Next = Temp;
}
Current = Temp;
Count++;
}
void main(void)
{
setlocale(LC_ALL,"Russian");
char buffer[15000];
char SubStr[128];
TSpisok A;
TSpisok Result;
TSpisok *tmp;
cout<<"Введите исходную строку : ";
cin.getline(buffer,1023);
strstream Str(buffer,strlen(buffer));
std::string S;
while (Str>> S)
{
A.Add(S);
}
cout<< "Список А: " << endl;
tmp = A.GetFirst();
while(tmp)
{
cout << tmp->GetWord() << " -> ";
tmp = tmp->NextPosition();
}
cout<< "[NULL]" << endl << endl;
cout << "Введите субстроку для поиска : ";
cin.getline(SubStr,127);
tmp = A.GetFirst();
while(tmp)
{
if (tmp->GetWord().find(SubStr) != string::npos)
{
Result.Add(tmp->GetWord());
}
tmp = tmp->NextPosition();
}
cout<< "Список Result: " << endl;
tmp = Result.GetFirst();
while(tmp)
{
cout << tmp->GetWord() << " -> ";
tmp = tmp->NextPosition();
}
cout<< "[NULL]" << endl << endl;
}