Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
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< N >
 Structure of List with supporting methods. More...
 

Namespaces

namespace  data_structures
 for IO operations
 
namespace  list_array
 Functions for Dynamic Array algorithm.
 

Functions

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

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
248 {
249 test(); // Execute the tests
250 return 0;
251}
static void test()
Test implementations.
Definition list_array.cpp:206
Here is the call graph for this function:

◆ test()

static void test ( )
static

Test implementations.

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