From bfeeea3beea5448eb9925cb5e108ec55090d91b3 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 26 Sep 2022 14:44:15 +0000 Subject: [PATCH] Documentation for 0febbf031480238d7612c2042580fb96c2b1a238 --- d9/d02/linear__search_8cpp.html | 156 +++++++++++++++++--------------- 1 file changed, 81 insertions(+), 75 deletions(-) diff --git a/d9/d02/linear__search_8cpp.html b/d9/d02/linear__search_8cpp.html index 6250ddf87..26a2700b4 100644 --- a/d9/d02/linear__search_8cpp.html +++ b/d9/d02/linear__search_8cpp.html @@ -178,16 +178,17 @@ Functions
-1 if key-value not found
22{
-
23 for (int i = 0; i < size; ++i)
+
23 for (int i = 0; i < size; ++i)
24 {
-
25 if (array[i] == key) {
-
26 return i;
-
27 }
-
28 }
-
29
-
30 /* We reach here only in case element is not present in array, return an invalid entry in that case*/
-
31 return -1;
-
32}
+
25 if (array[i] == key)
+
26 {
+
27 return i;
+
28 }
+
29 }
+
30
+
31 /* We reach here only in case element is not present in array, return an invalid entry in that case*/
+
32 return -1;
+
33}
@@ -209,55 +210,58 @@ Functions

Main function.

Returns
0 on exit
-
66 {
-
67 int mode = 0;
-
68
-
69 std::cout << "Choose mode\n";
-
70 std::cout << "Self-test mode (1), interactive mode (2): ";
-
71
-
72 std::cin >> mode;
+
71{
+
72 int mode = 0;
73
-
74 if (mode == 2) {
-
75 int size = 0;
-
76 std::cout << "\nEnter the size of the array: ";
-
77 std::cin >> size;
+
74 std::cout << "Choose mode\n";
+
75 std::cout << "Self-test mode (1), interactive mode (2): ";
+
76
+
77 std::cin >> mode;
78
-
79 while ((size <= 1) || (size >= 30)) {
-
80 std::cout << "Size cannot be less than zero. Please choose another value: ";
-
81 std::cin >> size;
-
82 }
-
83
-
84 int *array = new int[size];
-
85 int key = 0;
-
86
-
87 // Input for the array elements
-
88 std::cout << "Enter the array of " << size << " numbers: ";
-
89 for (int i = 0; i < size; i++) {
-
90 std::cin >> array[i];
-
91 }
+
79 if (mode == 2)
+
80 {
+
81 int size = 0;
+
82 std::cout << "\nEnter the size of the array [in range 1-30 ]: ";
+
83 std::cin >> size;
+
84
+
85 while (size <= 0 || size > 30){
+
86 std::cout << "Size can only be 1-30. Please choose another value: ";
+
87 std::cin >> size;
+
88 }
+
89
+
90 int *array = new int[size];
+
91 int key = 0;
92
-
93 std::cout << "\nEnter the number to be searched: ";
-
94 std::cin >> key;
-
95
-
96 int index = LinearSearch(array, size, key);
-
97 if (index != -1)
-
98 {
-
99 std::cout << "Number found at index: " << index << "\n";
-
100 }
-
101 else
-
102 {
-
103 std::cout << "Array element not found";
-
104 }
-
105 delete[] array;
-
106 }
-
107 else {
-
108 tests(); // run self-test implementations
-
109 }
-
110 return 0;
-
111}
+
93 // Input for the array elements
+
94 std::cout << "Enter the array of " << size << " numbers: ";
+
95 for (int i = 0; i < size; i++)
+
96 {
+
97 std::cin >> array[i];
+
98 }
+
99
+
100 std::cout << "\nEnter the number to be searched: ";
+
101 std::cin >> key;
+
102
+
103 int index = LinearSearch(array, size, key);
+
104 if (index != -1)
+
105 {
+
106 std::cout << "Number found at index: " << index << "\n";
+
107 }
+
108 else
+
109 {
+
110 std::cout << "Array element not found";
+
111 }
+
112 delete[] array;
+
113 }
+
114 else
+
115 {
+
116 tests(); // run self-test implementations
+
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
Here is the call graph for this function:
@@ -293,29 +297,31 @@ Here is the call graph for this function:

Self-test implementations.

Returns
void
-
38 {
-
39 int size = 4;
-
40 int *array = new int[size];
-
41 for (int i = 0; i < size; i++) {
-
42 array[i] = i;
-
43 }
-
44
-
45 assert(LinearSearch(array, size, 0) == 0);
-
46 assert(LinearSearch(array, size, 1) == 1);
-
47 assert(LinearSearch(array, size, 2) == 2);
-
48
-
49 size = 6;
-
50 for (int i = 0; i < size; i++) {
-
51 array[i] = i;
-
52 }
-
53
-
54 assert(LinearSearch(array, size, 3) == 3);
-
55 assert(LinearSearch(array, size, 1) == 1);
-
56 assert(LinearSearch(array, size, 5) == 5);
+
40{
+
41 int size = 4;
+
42 int *array = new int[size];
+
43 for (int i = 0; i < size; i++)
+
44 {
+
45 array[i] = i;
+
46 }
+
47
+
48 assert(LinearSearch(array, size, 0) == 0);
+
49 assert(LinearSearch(array, size, 1) == 1);
+
50 assert(LinearSearch(array, size, 2) == 2);
+
51
+
52 size = 6;
+
53 for (int i = 0; i < size; i++)
+
54 {
+
55 array[i] = i;
+
56 }
57
-
58 std::cout << "All tests have successfully passed!\n";
-
59 delete[] array; // free memory up
-
60}
+
58 assert(LinearSearch(array, size, 3) == 3);
+
59 assert(LinearSearch(array, size, 1) == 1);
+
60 assert(LinearSearch(array, size, 5) == 5);
+
61
+
62 std::cout << "All tests have successfully passed!\n";
+
63 delete[] array; // free memory up
+
64}
Here is the call graph for this function: