From 2fe7e4add0d4939d6553552d0714ec99d93f1683 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Tue, 23 Jun 2020 11:43:28 -0400 Subject: [PATCH 1/4] fix function return + add docs --- data_structures/list_array.cpp | 75 +++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/data_structures/list_array.cpp b/data_structures/list_array.cpp index c796ffef9..4c6855a51 100644 --- a/data_structures/list_array.cpp +++ b/data_structures/list_array.cpp @@ -1,5 +1,9 @@ +/** + * @file list_array.cpp + * @todo Add documentation + * @warning The sorting algorithm is erroneous + */ #include -using namespace std; struct list { int data[50]; @@ -17,6 +21,9 @@ struct list { return (BinarySearch(array, first, mid - 1, x)); else if (x > array[mid]) return (BinarySearch(array, mid + 1, last, x)); + + std::cerr << __func__ << ":" << __LINE__ << ": Undefined condition\n"; + return -1; } int LinarSearch(int *array, int x) { @@ -41,9 +48,9 @@ struct list { } if (pos != -1) { - cout << "\nElement found at position : " << pos; + std::cout << "\nElement found at position : " << pos; } else { - cout << "\nElement not found"; + std::cout << "\nElement not found"; } return pos; } @@ -69,7 +76,7 @@ struct list { void insert(int x) { if (!isSorted) { if (top == 49) { - cout << "\nOverflow"; + std::cout << "\nOverflow"; } else { data[top] = x; top++; @@ -99,7 +106,7 @@ struct list { void Remove(int x) { int pos = Search(x); - cout << "\n" << data[pos] << " deleted"; + std::cout << "\n" << data[pos] << " deleted"; for (int i = pos; i < top; i++) { data[i] = data[i + 1]; } @@ -108,7 +115,7 @@ struct list { void Show() { for (int i = 0; i < top; i++) { - cout << data[i] << "\t"; + std::cout << data[i] << "\t"; } } }; @@ -118,35 +125,35 @@ int main() { int choice; int x; do { - cout << "\n1.Insert"; - cout << "\n2.Delete"; - cout << "\n3.Search"; - cout << "\n4.Sort"; - cout << "\n5.Print"; - cout << "\n\nEnter Your Choice : "; - cin >> choice; + std::cout << "\n1.Insert"; + std::cout << "\n2.Delete"; + std::cout << "\n3.Search"; + std::cout << "\n4.Sort"; + std::cout << "\n5.Print"; + std::cout << "\n\nEnter Your Choice : "; + std::cin >> choice; switch (choice) { - case 1: - cout << "\nEnter the element to be inserted : "; - cin >> x; - L.insert(x); - break; - case 2: - cout << "\nEnter the element to be removed : "; - cin >> x; - L.Remove(x); - break; - case 3: - cout << "\nEnter the element to be searched : "; - cin >> x; - L.Search(x); - break; - case 4: - L.Sort(); - break; - case 5: - L.Show(); - break; + case 1: + std::cout << "\nEnter the element to be inserted : "; + std::cin >> x; + L.insert(x); + break; + case 2: + std::cout << "\nEnter the element to be removed : "; + std::cin >> x; + L.Remove(x); + break; + case 3: + std::cout << "\nEnter the element to be searched : "; + std::cin >> x; + L.Search(x); + break; + case 4: + L.Sort(); + break; + case 5: + L.Show(); + break; } } while (choice != 0); return 0; From 497ede21e0d29aa2a8b856289dfa24dec3751dc2 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Tue, 23 Jun 2020 11:45:16 -0400 Subject: [PATCH 2/4] fix function return --- data_structures/trie_tree.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data_structures/trie_tree.cpp b/data_structures/trie_tree.cpp index 66b67fbc0..a613ebd8f 100644 --- a/data_structures/trie_tree.cpp +++ b/data_structures/trie_tree.cpp @@ -74,6 +74,10 @@ bool deleteString(trie* root, std::string str, int index) { return true; } } + + /* should not return here */ + std::cout << __func__ << ":" << __LINE__ << "Should not reach this line\n"; + return false; } int main() { From 56cb22cd444aa1c24dffbbdd2356945dc873d362 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Tue, 23 Jun 2020 15:46:52 +0000 Subject: [PATCH 3/4] formatting source-code for 497ede21e0d29aa2a8b856289dfa24dec3751dc2 --- data_structures/list_array.cpp | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/data_structures/list_array.cpp b/data_structures/list_array.cpp index 4c6855a51..c49e17e06 100644 --- a/data_structures/list_array.cpp +++ b/data_structures/list_array.cpp @@ -133,27 +133,27 @@ int main() { std::cout << "\n\nEnter Your Choice : "; std::cin >> choice; switch (choice) { - case 1: - std::cout << "\nEnter the element to be inserted : "; - std::cin >> x; - L.insert(x); - break; - case 2: - std::cout << "\nEnter the element to be removed : "; - std::cin >> x; - L.Remove(x); - break; - case 3: - std::cout << "\nEnter the element to be searched : "; - std::cin >> x; - L.Search(x); - break; - case 4: - L.Sort(); - break; - case 5: - L.Show(); - break; + case 1: + std::cout << "\nEnter the element to be inserted : "; + std::cin >> x; + L.insert(x); + break; + case 2: + std::cout << "\nEnter the element to be removed : "; + std::cin >> x; + L.Remove(x); + break; + case 3: + std::cout << "\nEnter the element to be searched : "; + std::cin >> x; + L.Search(x); + break; + case 4: + L.Sort(); + break; + case 5: + L.Show(); + break; } } while (choice != 0); return 0; From 8575e21e73d5286b1c05cbe8b70f77997f0b0a2f Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Tue, 23 Jun 2020 11:50:12 -0400 Subject: [PATCH 4/4] fix lint errors --- data_structures/list_array.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/data_structures/list_array.cpp b/data_structures/list_array.cpp index c49e17e06..24b04867b 100644 --- a/data_structures/list_array.cpp +++ b/data_structures/list_array.cpp @@ -41,9 +41,7 @@ struct list { if (isSorted) { pos = BinarySearch(data, 0, top - 1, x); - } - - else { + } else { pos = LinarSearch(data, x); } @@ -81,9 +79,7 @@ struct list { data[top] = x; top++; } - } - - else { + } else { int pos = 0; for (int i = 0; i < top - 1; i++) {