diff --git a/data_structures/list_array.cpp b/data_structures/list_array.cpp index 0c8099f578..d53af391ec 100644 --- a/data_structures/list_array.cpp +++ b/data_structures/list_array.cpp @@ -46,7 +46,7 @@ struct list { * @param val element that will be searched * @return index of element in the list if present else -1 */ - uint64_t BinarySearch(const std::array &dataArr, + int64_t BinarySearch(const std::array &dataArr, const uint64_t &first, const uint64_t &last, const uint64_t &val) { // If both pointer cross each other means no element present in the list @@ -77,7 +77,7 @@ struct list { * @param val element that will be searched * @return index of element in the list if present else -1 */ - uint64_t LinearSearch(const std::array &dataArr, + int64_t LinearSearch(const std::array &dataArr, const uint64_t &val) const { // Going through each element in the list for (uint64_t i = 0; i < top; i++) { @@ -94,8 +94,8 @@ struct list { * @param val element that will be searched * @return index of element in the list if present else -1 */ - uint64_t search(const uint64_t &val) { - uint64_t pos; // pos variable to store index value of element. + int64_t search(const uint64_t &val) { + int64_t pos; // pos variable to store index value of element. // if list is sorted, binary search works efficiently else linear search // is the only option if (isSorted) { @@ -181,7 +181,7 @@ struct list { * @returns void */ void remove(const uint64_t &val) { - uint64_t pos = search(val); // search the index of the value + int64_t pos = search(val); // search the index of the value // if search returns -1, element does not present in the list if (pos == -1) { std::cout << "\n Element does not present in the list "; diff --git a/data_structures/queue_using_array.cpp b/data_structures/queue_using_array.cpp index c243725832..80d8b048b3 100644 --- a/data_structures/queue_using_array.cpp +++ b/data_structures/queue_using_array.cpp @@ -57,13 +57,13 @@ class Queue_Array { * @param ele to be added to the end of the queue */ void Queue_Array::enqueue(const int16_t& ele) { - if (rear == arr.size() - 1) { + if (rear == static_cast(arr.size()) - 1) { std::cout << "\nStack is full"; } else if (front == -1 && rear == -1) { front = 0; rear = 0; arr[rear] = ele; - } else if (rear < arr.size()) { + } else if (rear < static_cast(arr.size())) { ++rear; arr[rear] = ele; } diff --git a/data_structures/trie_tree.cpp b/data_structures/trie_tree.cpp index b7b4ce5fd5..feb2c038bd 100644 --- a/data_structures/trie_tree.cpp +++ b/data_structures/trie_tree.cpp @@ -54,7 +54,7 @@ class trie { * @returns `false` if not found */ bool search(const std::shared_ptr& root, const std::string& str, - int index) { + size_t index) { if (index == str.length()) { if (!root->isEndofWord) { return false; @@ -104,7 +104,7 @@ class trie { * @returns `true` if found * @returns `false` if not found */ - bool search(const std::string& str, int index) { + bool search(const std::string& str, size_t index) { if (index == str.length()) { if (!isEndofWord) { return false; @@ -131,7 +131,7 @@ class trie { * @returns `true` if successful * @returns `false` if unsuccessful */ - bool deleteString(const std::string& str, int index) { + bool deleteString(const std::string& str, size_t index) { if (index == str.length()) { if (!isEndofWord) { return false;