Skip to content

CPP header file that allows users to sort an array using their chosen sorting algorithm and then perform a search to find the index of a given element.

Notifications You must be signed in to change notification settings

Symbian-Bro/array-header

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a header file that can be used with your C++ programs. Pass the values such as size of the array, the array, the element user wants to find and the search function of user's choice. The array passed will get sorted automatically as there is a selection sorting algorithm within this file(If the user chooses binary search). Then the sorted array will be passed to the desired function.

How to use :

  • Place this file inside your working directory
  • Use #include "arrayheader.h" to add this file to the headers
  • Pass all the neccessary values to the selection function

Return values :

  • -1 if the element is not found
  • -2 if the user's choice of searching mechanism is invalid
  • All other values returned are the indices of the element you are searching for

Example implementation :

int index = selection(size, arr, element, choice);

if(index != -1 && index != -2) {
    std::cout << "Element " << element << " found at index: " << index << "\n";
} else if(index == -1) {
    std::cout << "Element " << element << " not found.\n";
} else if(index == -2) {
    std::cout << "Invalid choice for search algorithm.\n";
}

About

CPP header file that allows users to sort an array using their chosen sorting algorithm and then perform a search to find the index of a given element.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published