Structure of List with supporting methods.
More...
|
| uint64_t | BinarySearch (const std::array< uint64_t, 50 > &dataArr, const uint64_t &first, const uint64_t &last, const uint64_t &val) |
| | Search an element in the list using binarySearch. More...
|
| |
| uint64_t | LinearSearch (const std::array< uint64_t, 50 > &dataArr, const uint64_t &val) const |
| | Search an element using linear search. More...
|
| |
|
uint64_t | search (const uint64_t &val) |
| |
| void | sort () |
| | Sort the list. More...
|
| |
| void | insert (const uint64_t &val) |
| | Insert the new element in the list. More...
|
| |
| void | remove (const uint64_t &val) |
| | To remove the element from the list. More...
|
| |
| void | show () |
| | Utility function to print array. More...
|
| |
|
|
std::array< uint64_t, 50 > | data {} |
| |
|
uint64_t | top = 0 |
| |
|
bool | isSorted = false |
| |
Structure of List with supporting methods.
◆ BinarySearch()
| uint64_t data_structures::list_array::list::BinarySearch |
( |
const std::array< uint64_t, 50 > & |
dataArr, |
|
|
const uint64_t & |
first, |
|
|
const uint64_t & |
last, |
|
|
const uint64_t & |
val |
|
) |
| |
|
inline |
Search an element in the list using binarySearch.
- Parameters
-
| dataArr | list |
| first | pointer to the first element in the remaining list |
| last | pointer to the last element in the remaining list |
| val | element that will be searched |
- Returns
- index of element in the list if present else -1
50 uint64_t mid = (first + last) / 2;
52 if (dataArr[mid] == val)
55 else if (val < dataArr[mid])
58 else if (val > dataArr[mid])
61 std::cerr << __func__ <<
":" << __LINE__ <<
": Undefined condition\n";
uint64_t BinarySearch(const std::array< uint64_t, 50 > &dataArr, const uint64_t &first, const uint64_t &last, const uint64_t &val)
Search an element in the list using binarySearch.
Definition: list_array.cpp:44
◆ insert()
| void data_structures::list_array::list::insert |
( |
const uint64_t & |
val | ) |
|
|
inline |
Insert the new element in the list.
- Parameters
-
| val | element that will be inserted |
- Returns
- void
146 for (uint64_t i = 0; i < top - 1; i++) {
148 if (data[i] <= val && val <= data[i + 1]) {
158 for (uint64_t i = top; i > pos; i--) {
159 data[i] = data[i - 1];
◆ LinearSearch()
| uint64_t data_structures::list_array::list::LinearSearch |
( |
const std::array< uint64_t, 50 > & |
dataArr, |
|
|
const uint64_t & |
val |
|
) |
| const |
|
inline |
Search an element using linear search.
- Parameters
-
| dataArr | list |
| val | element that will be searched |
- Returns
- index of element in the list if present else -1
73 for (uint64_t i = 0; i < top; i++) {
74 if (dataArr[i] == val) {
◆ remove()
| void data_structures::list_array::list::remove |
( |
const uint64_t & |
val | ) |
|
|
inline |
To remove the element from the list.
- Parameters
-
| val | element that will be removed |
- Returns
- void
172 uint64_t pos =
search(val);
175 std::cout <<
"\n Element does not present in the list ";
178 std::cout <<
"\n" << data[pos] <<
" deleted";
180 for (uint64_t i = pos; i < top; i++) {
int data[MAX]
test data
Definition: hash_search.cpp:24
◆ show()
| void data_structures::list_array::list::show |
( |
| ) |
|
|
inline |
Utility function to print array.
- Returns
- void
193 for (uint64_t i = 0; i < top; i++) {
◆ sort()
| void data_structures::list_array::list::sort |
( |
| ) |
|
|
inline |
Sort the list.
- Returns
- void
112 for (uint64_t i = 0; i < top; i++) {
113 uint64_t min_idx = i;
114 for (uint64_t j = i + 1; j < top; j++) {
116 if (data[j] < data[min_idx]) {
The documentation for this struct was generated from the following file: