Merge branch 'master' into my-algo-contribution

This commit is contained in:
David Leal 2022-09-26 10:01:13 -05:00 committed by GitHub
commit d67d450c38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,7 +22,8 @@ int LinearSearch(int *array, int size, int key)
{
for (int i = 0; i < size; ++i)
{
if (array[i] == key) {
if (array[i] == key)
{
return i;
}
}
@ -35,10 +36,12 @@ int LinearSearch(int *array, int size, int key)
* @brief Self-test implementations
* @returns void
*/
static void tests() {
static void tests()
{
int size = 4;
int *array = new int[size];
for (int i = 0; i < size; i++) {
for (int i = 0; i < size; i++)
{
array[i] = i;
}
@ -47,7 +50,8 @@ static void tests() {
assert(LinearSearch(array, size, 2) == 2);
size = 6;
for (int i = 0; i < size; i++) {
for (int i = 0; i < size; i++)
{
array[i] = i;
}
@ -63,7 +67,8 @@ static void tests() {
* @brief Main function
* @returns 0 on exit
*/
int main() {
int main()
{
int mode = 0;
std::cout << "Choose mode\n";
@ -71,13 +76,14 @@ int main() {
std::cin >> mode;
if (mode == 2) {
if (mode == 2)
{
int size = 0;
std::cout << "\nEnter the size of the array: ";
std::cout << "\nEnter the size of the array [in range 1-30 ]: ";
std::cin >> size;
while ((size <= 1) || (size >= 30)) {
std::cout << "Size cannot be less than zero. Please choose another value: ";
while (size <= 0 || size > 30){
std::cout << "Size can only be 1-30. Please choose another value: ";
std::cin >> size;
}
@ -86,7 +92,8 @@ int main() {
// Input for the array elements
std::cout << "Enter the array of " << size << " numbers: ";
for (int i = 0; i < size; i++) {
for (int i = 0; i < size; i++)
{
std::cin >> array[i];
}
@ -104,7 +111,8 @@ int main() {
}
delete[] array;
}
else {
else
{
tests(); // run self-test implementations
}
return 0;