From 4b3749ed49d863bbfd2090c56151586962c7b78d Mon Sep 17 00:00:00 2001 From: sprintyaf Date: Tue, 7 Jul 2020 17:59:49 +0400 Subject: [PATCH] variable-length arrays fixed --- search/fibonacci_search.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/search/fibonacci_search.cpp b/search/fibonacci_search.cpp index 5cdc93ae9..f8525a6b4 100644 --- a/search/fibonacci_search.cpp +++ b/search/fibonacci_search.cpp @@ -67,7 +67,7 @@ bool one_occurence_test(){ bool passed = true; // last element length = 3; - int arr1[length] = {1, 2, 3}; + int arr1[3] = {1, 2, 3}; value = 3; index = fibonacci_search(arr1, value, length); passed = passed && (index == 2); @@ -77,13 +77,13 @@ bool one_occurence_test(){ passed = passed && (index == 0); // somewhere in the middle element length = 4; - int arr2[length] = {1, 3, 5, 7}; + int arr2[4] = {1, 3, 5, 7}; value = 3; index = fibonacci_search(arr2, value, length); passed = passed && (index == 1); // arr size is 1 length = 1; - int arr3[length] = {10}; + int arr3[1] = {10}; value = 10; index = fibonacci_search(arr3, value, length); passed = passed && (index == 0); @@ -100,7 +100,7 @@ bool many_occurence_test(){ bool passed = true; // last element length = 4; - int arr1[length] = {1, 1, 10, 10}; + int arr1[4] = {1, 1, 10, 10}; value = 10; index = fibonacci_search(arr1, value, length); passed = passed && (index == 2 || index == 3); @@ -110,13 +110,13 @@ bool many_occurence_test(){ passed = passed && (index == 0 || index == 1); // somewhere in the middle element length = 4; - int arr2[length] = {1, 3, 3, 7}; + int arr2[4] = {1, 3, 3, 7}; value = 3; index = fibonacci_search(arr2, value, length); passed = passed && (index == 1 || index == 2); // all elements are the same length = 3; - int arr3[length] = {10, 10, 10}; + int arr3[3] = {10, 10, 10}; value = 10; index = fibonacci_search(arr3, value, length); passed = passed && (index >= 0 && index <= 2); @@ -133,19 +133,19 @@ bool no_occurence_test(){ bool passed = true; // many elements length = 4; - int arr1[length] = {1, 2, 4, 5}; + int arr1[4] = {1, 2, 4, 5}; value = 3; index = fibonacci_search(arr1, value, length); passed = passed && (index == -1); // one element length = 1; - int arr2[length] = {1}; + int arr2[1] = {1}; value = 2; index = fibonacci_search(arr2, value, length); passed = passed && (index == -1); // empty array length = 0; - int arr3[length]; + int arr3[10] = {}; value = 10; index = fibonacci_search(arr3, value, length); passed = passed && (index == -1);