1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include <iostream>
#include<string>
using namespace std;
class AlbumNode
{
int year;
string artist;
string name;
string genre;
string label;
AlbumNode *next;
AlbumNode() : next(0) {};
AlbumNode(int y, string t, string a, string g, string b) : next(0) { year = y; name = a; genre = g; label = b; };
friend class AlbumList;
friend void operator<<(ostream& os, const AlbumList& L);
};
class AlbumList {
public:
AlbumNode *root = NULL;
bool Search(string n)
{
AlbumNode *current = root;
while (current)
{
if (current->name == n) return true;
else current = current->next;
}
return false;
};
void Add(int y, string t, string a, string g, string b)
{
AlbumNode *temp = new AlbumNode(y, t, a, g, b);
temp->next = root;
root = temp;
return;
};
AlbumNode* CopyNode(AlbumNode *n)
{
AlbumNode *temp = new AlbumNode();
if (n->next) temp->next = CopyNode(n->next);
return temp;
};
void Print(ostream& os)
{
return DoPrint(os, root);
};
void DoPrint(ostream& os, AlbumNode* n) const
{
if (n->next)
DoPrint(os, n->next);
os << "\t" << n->year << "\t" << n->artist << "\t" << n->name << "\t" << n->genre << "\t" << n->label << "\t" << "\t";
};
friend void operator << (ostream& os, const AlbumList& L);
};
void operator << (ostream& os, const AlbumList& L)
{
os << " [ ";
AlbumNode *current = L.root;
//L.Print(os);
while (current)
{
os << current->year << current->artist << current->name << current->genre << current->label << "\t";
current = current->next;
}
os << "]";
};
int main()
{
AlbumList L;
L.Add(1968, "\tThe Beatles", "\tThe White Album", "\tApple Records", "\tRock");
cout << L;
if (L.Search("\tThe White Album"))
cout << "Yes Found" << endl;
else
cout << "Not Found" << endl;
// AlbumList L; cout << L;
}
|