Sorting Students Names

  1. Modify your previous program. As a list of student names are being read into the program, sort them so that they will be printed out in ascending order.
  2. You may re-use the skill of binary tree in an earlier exercise. However, in this exercise, each node contains a data member of type CStudent, instead of a simple integer:
    
    class CNode
    {
    public:
        CStudent m_student;
        CNode* m_pLeft;
        CNode* m_pRight;
    };
    
    
  3. Slightly modify the functions insertToTree(CNode*& pNode, CStudent s) and printTree(CNode* p) so that they will create an ascending list and print the list out, respectively.
  4. To compare two students, you may need to define a function operator<() or operator>(). This is the Operator Overloading technique which you learned in Chapter 8.
  5. The results show that English names are displayed before Chinese names, because the UTF-8 code of Chinese characters are larger than English characters (ASCII code 65~90).

For example, the input

東坡 蘇
Sandra Bullock
宗元 柳
Julia Roberts

will generate the following output:

Julia Roberts
Sandra Bullock
柳宗元
蘇東坡