Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
list_array.cpp File Reference

Dynamic Array More...

#include <iostream>
#include <array>
#include <cassert>
Include dependency graph for list_array.cpp:

Classes

struct  data_structures::list_array::list
 Structure of List with supporting methods. More...
 

Namespaces

namespace  data_structures
 Data Structures algorithms.
 
namespace  list_array
 Functions for Dynamic Array algorithm.
 

Functions

static void test ()
 Test implementations. More...
 
int main ()
 Main function. More...
 

Detailed Description

Dynamic Array

The list_array is the implementation of list represented using array. We can perform basic CRUD operations as well as other operations like sorting etc.

Algorithm

It implements various method like insert, sort, search etc. efficiently. You can select the operation and methods will do the rest work for you. You can insert element, sort them in order, search efficiently, delete values and print the list.

Function Documentation

◆ main()

int main ( void  )

Main function.

Returns
0 on exit
247 {
248 test(); // Execute the tests
249 return 0;
250}
static void test()
Test implementations.
Definition: list_array.cpp:205
Here is the call graph for this function:

◆ test()

static void test ( )
static

Test implementations.

Returns
void
205 {
207
208 // Insert testing
209 L.insert(11);
210 L.insert(12);
211 assert(L.top == 2);
212 L.insert(15);
213 L.insert(10);
214 L.insert(12);
215 L.insert(20);
216 L.insert(18);
217 assert(L.top == 7);
218 L.show(); // To print the array
219
220 // Remove testing
221 L.remove(12); // Remove Duplicate value in the list
222 L.remove(15); // Remove the existing value in the list
223 assert(L.top == 5);
224 L.remove(50); // Try to remove the non-existing value in the list
225 assert(L.top == 5);
226
227 // LinearSearch testing
228 assert(L.search(11) == 0); // search for the existing element
229 assert(L.search(12) == 2);
230 assert(L.search(50) == -1); // search for the non-existing element
231
232 // Sort testing
233 L.sort();
234 assert(L.isSorted == true);
235 L.show();
236
237 // BinarySearch testing
238 assert(L.search(11) == 1); // search for the existing element
239 assert(L.search(12) == 2);
240 assert(L.search(50) == -1); // search for the non-existing element
241}
Structure of List with supporting methods.
Definition: list_array.cpp:32
void remove(const uint64_t &val)
To remove the element from the list.
Definition: list_array.cpp:171
void insert(const uint64_t &val)
Insert the new element in the list.
Definition: list_array.cpp:132
void sort()
Sort the list.
Definition: list_array.cpp:110
void show()
Utility function to print array.
Definition: list_array.cpp:190
Here is the call graph for this function: