C++ sorting a tree by alphabetical order?

  alphabetical, c++, quicksort, sorting

Ive created a quick sort program that sorts a text file by the count in descending order. So like this

apple: 5
hi:4
flower: 3
bye: 2
Jake: 1

However some words may have the same count, like apple:5 and adam:5 so id like to futher sort the tree in alphabetical order but un sure of the implementation. Below is my quicksort

It would be sorted by key.

struct node
{
    std::string key;
    struct node *left;
    struct node *right;
    int height;
    int count = 0;
};
int partition (int arr[], int low, int high) {

    int pivot = arr[high]; 
    int i = (low - 1);  
    
    for (int j = low; j <= high- 1; j++) 
    { 
       //checks if current element is smaller than the pivt 
        if (arr[j] > pivot) 
        { 
            i++;    
            doSwap(wordArr[i],wordArr[j]);
            swap(&arr[i], &arr[j]); 
        } 
    } 
    doSwap(wordArr[i+1],wordArr[high]);
    swap(&arr[i + 1], &arr[high]); 
    return (i + 1); 
}

void quickSort(int arr[], int low, int high) {

if (low < high) 
    {  
        int pi = partition(arr, low, high); 
  
        quickSort(arr, low, pi - 1); 
        quickSort(arr, pi + 1, high);
}
}

How can i modify this so it also sorts alphabetically? Thankyou
EDIT:This is for a uni task so we cant use any STL

Source: Windows Questions C++

LEAVE A COMMENT