TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
list_array.cpp File Reference

Dynamic Array More...

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

Go to the source code of this file.

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.

Definition in file list_array.cpp.

Function Documentation

◆ main()

int main ( void )

Main function.

Returns
0 on exit

Definition at line 260 of file list_array.cpp.

260 {
261 test(); // Execute the tests
262 return 0;
263}
static void test()
Test implementations.

◆ test()

static void test ( )
static

Test implementations.

Returns
void

Definition at line 218 of file list_array.cpp.

218 {
220
221 // Insert testing
222 L.insert(11);
223 L.insert(12);
224 assert(L.top == 2);
225 L.insert(15);
226 L.insert(10);
227 L.insert(12);
228 L.insert(20);
229 L.insert(18);
230 assert(L.top == 7);
231 L.show(); // To print the array
232
233 // Remove testing
234 L.remove(12); // Remove Duplicate value in the list
235 L.remove(15); // Remove the existing value in the list
236 assert(L.top == 5);
237 L.remove(50); // Try to remove the non-existing value in the list
238 assert(L.top == 5);
239
240 // LinearSearch testing
241 assert(L.search(11) == 0); // search for the existing element
242 assert(L.search(12) == 2);
243 assert(L.search(50) == -1); // search for the non-existing element
244
245 // Sort testing
246 L.sort();
247 assert(L.isSorted == true);
248 L.show();
249
250 // BinarySearch testing
251 assert(L.search(11) == 1); // search for the existing element
252 assert(L.search(12) == 2);
253 assert(L.search(50) == -1); // search for the non-existing element
254}
Structure of List with supporting methods.
void show()
Utility function to print array.
void remove(const uint64_t &val)
To remove the element from the list.
void insert(const uint64_t &val)
Insert the new element in the list.