Sort Problem!

Absolute Zero

Well-known member
  • Mar 31, 2015
    13,261
    1
    16,807
    113
    −273.15°C
    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]
     

    Pessimist

    Well-known member
  • Mar 6, 2018
    20,665
    1,562
    113
    🌎
    ඇයි බං ඔහොම කලේ ? vector එකකට වගේ දාගත්ත නං හරිනෙ. print වෙද්දි සෝට් වෙලා print කරන්න බෑ. උඹට ලිස්ට් එකේ මුල nextbook එක බල බල මෙහාට ගන්න වෙනව.

    නැත්තං printlist function එක ඇතුලෙ print කරනව වෙනුවට ඔක්කොගම titles vector එකකට දාගෙන යන්න. දාල ඒක සෝට් කරල print කරන්න.
     

    SPACEBAR

    Member
    Apr 30, 2014
    3,344
    1,039
    0
    ☢☢ⓚⓔⓨⓑⓞⓐⓡⓓ☢☢
    gee0j5s.gif