71{
+
72 int mode = 0;
73
-
74 if (mode == 2) {
-
75 int size = 0;
-
76 std::cout <<
"\nEnter the size of the array: ";
-
+
+
75 std::cout <<
"Self-test mode (1), interactive mode (2): ";
+
76
+
78
-
79 while ((size <= 1) || (size >= 30)) {
-
80 std::cout <<
"Size cannot be less than zero. Please choose another value: ";
-
-
82 }
-
83
-
84 int *array = new int[size];
-
85 int key = 0;
-
86
-
87
-
88 std::cout <<
"Enter the array of " << size <<
" numbers: ";
-
89 for (int i = 0; i < size; i++) {
-
-
91 }
+
79 if (mode == 2)
+
80 {
+
81 int size = 0;
+
82 std::cout <<
"\nEnter the size of the array [in range 1-30 ]: ";
+
+
84
+
85 while (size <= 0 || size > 30){
+
86 std::cout <<
"Size can only be 1-30. Please choose another value: ";
+
+
88 }
+
89
+
90 int *array = new int[size];
+
91 int key = 0;
92
-
93 std::cout <<
"\nEnter the number to be searched: ";
-
-
95
-
-
97 if (index != -1)
-
98 {
-
99 std::cout <<
"Number found at index: " << index <<
"\n";
-
100 }
-
101 else
-
102 {
-
-
104 }
-
105 delete[] array;
-
106 }
-
107 else {
-
-
109 }
-
110 return 0;
-
111}
+
93
+
94 std::cout <<
"Enter the array of " << size <<
" numbers: ";
+
95 for (int i = 0; i < size; i++)
+
96 {
+
+
98 }
+
99
+
100 std::cout <<
"\nEnter the number to be searched: ";
+
+
102
+
+
104 if (index != -1)
+
105 {
+
106 std::cout <<
"Number found at index: " << index <<
"\n";
+
107 }
+
108 else
+
109 {
+
+
111 }
+
112 delete[] array;
+
113 }
+
114 else
+
115 {
+
+
117 }
+
118 return 0;
+
119}
-
static void tests()
Self-test implementations.
Definition: linear_search.cpp:38
+
static void tests()
Self-test implementations.
Definition: linear_search.cpp:39
int LinearSearch(int *array, int size, int key)
for assert
Definition: linear_search.cpp:21