File Handling එක්ක යන මෙ කොඩ් එක printList() එකෙදි Book Title එක(Alphabetically... etc) සොර්ට් කරගන්නෙ කොහොමද?
Code:
class book
{
public:
string title;
string author;
int year;
book* next;
book(string, string, int, book*);
};
book::book(string tempTitle, string tempAuthor, int tempYear, book* tempNext)
{
title=tempTitle;
author=tempAuthor;
year=tempYear;
next=tempNext;
}
typedef book* bookPtr;
void getline(istream &stream, string &str, char delimiter)
{ char temp[500];
stream.get(temp, 500, delimiter);
stream.ignore(500, delimiter);
str = temp;
}
void getline(istream &stream, int &num, char delimiter)
{ int temp;
stream >> temp;
stream.ignore(500, delimiter);
num= temp;
}
void insert (bookPtr &root)
{
string titl, aut;
int yea;
cout << "Title:\t\t\t";
cin.ignore(500,'\n');
getline(cin, titl, '\n');
cout << "Author:\t\t\t";
getline(cin, aut, '\n');
cout << "Year:\t\t\t";
getline(cin, yea, '\n');
root = new book (titl, aut, yea, root);
}
[COLOR=Magenta]void printList(bookPtr temp)
{
while (temp != NULL)
{
cout << temp->title << "\n";
temp = temp->next;
}
cout << "\n";
}[/COLOR]