jeudi 22 mars 2018

c++ employee name search

        string name[size] = {"Collins, Bill", "Smith, Bart", "Michalski, Joe", "Griffin, Jim",
                "Sanchez, Manny", "Rubin, Sarah", "Taylor, Tyrone", "Johnson, Jill",
                "Allison, Jeff", "Moreno, Juan", "Wolfe, Bill", "Whitman, Jean",
                "Moretti, Bella", "Wu, Hong", "Patel, Renee", "Harrison, Rose",
                "Smith, Cathy", "Conroy, Pat", "Kelly, Sean", "Holland, Beth"};



    int binarySearchIterative(string name[], int size, string empName) {
        int low = 0;
        int high = size - 1;

        while (low <= high) {
            int mid = (low + high) / 2;
            if (empName == name[mid]) {
                return mid;
            } else if (empName < name[mid]) {
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        return -1;
    }

So when I type in a name to search for, I have to type it in exactly as listed in the array. For example, if I want to find Bill Collins. I have to type it as Collins, Bill. If I were to type in Bill Collins, it would tell me that the employee is not found. I need to be able to search the name First Last, and also without using the comma. If you need to see more of my code let me know.

Aucun commentaire:

Enregistrer un commentaire