|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Linear data structures: Stack, Queue, DynArray, DynList. More...
#include <iostream>#include <string>#include <tpl_dynListStack.H>#include <tpl_dynListQueue.H>#include <tpl_dynArray.H>#include <tpl_dynList.H>#include <tpl_dynDlist.H>#include <tpl_arrayStack.H>#include <tpl_arrayQueue.H>Go to the source code of this file.
Functions | |
| void | demo_stack () |
| void | demo_queue () |
| void | demo_dynarray () |
| void | demo_dynlist () |
| void | demo_comparison () |
| int | main () |
Linear data structures: Stack, Queue, DynArray, DynList.
This example demonstrates the fundamental linear (one-dimensional) data structures in Aleph-w. These are the building blocks for more complex algorithms and data structures. Understanding these is essential for effective programming.
Linear data structures organize elements in a sequence where each element (except the first and last) has exactly one predecessor and one successor. They differ in how elements are accessed and modified.
A stack is like a stack of plates: you add to the top and remove from the top.
A queue is like a line at a store: first person in is first person out.
A resizable array that grows automatically as needed.
Linked lists that grow dynamically with efficient insertion/deletion.
| Operation | Array | List | Stack | Queue |
|---|---|---|---|---|
| Access by index | O(1) | O(n) | N/A | N/A |
| Insert at end | O(1)* | O(1) | O(1) | O(1) |
| Insert at middle | O(n) | O(1) | N/A | N/A |
| Delete at middle | O(n) | O(1) | N/A | N/A |
| Memory overhead | Low | High | Medium | Medium |
*Amortized for dynamic arrays
Definition in file linear_structures_example.C.
| void demo_comparison | ( | ) |
Definition at line 459 of file linear_structures_example.C.
References Aleph::DynListQueue< T >::get(), Aleph::DynListQueue< T >::is_empty(), Aleph::DynListStack< T >::is_empty(), Aleph::maps(), Aleph::DynListStack< T >::pop(), Aleph::DynListStack< T >::push(), and Aleph::DynListQueue< T >::put().
Referenced by main().
| void demo_dynarray | ( | ) |
Definition at line 330 of file linear_structures_example.C.
References Aleph::DynArray< T >::append(), Aleph::DynList< T >::append(), FunctionalMethods< Container, T >::filter(), FunctionalMethods< Container, T >::foldl(), FunctionalMethods< Container, T >::for_each(), Aleph::maps(), FunctionalMethods< Container, T >::maps(), Aleph::DynArray< T >::size(), and Aleph::sum().
Referenced by main().
| void demo_dynlist | ( | ) |
Definition at line 402 of file linear_structures_example.C.
References Aleph::DynList< T >::append(), Aleph::DynDlist< T >::append(), FunctionalMethods< Container, T >::for_each(), Aleph::DynList< T >::insert(), Aleph::maps(), Aleph::DynDlist< T >::remove_first(), Aleph::DynDlist< T >::remove_last(), and Aleph::HTList::size().
Referenced by main().
| void demo_queue | ( | ) |
Definition at line 272 of file linear_structures_example.C.
References Aleph::DynListQueue< T >::front(), Aleph::DynList< T >::get(), Aleph::DynListQueue< T >::get(), Aleph::HTList::is_empty(), Aleph::DynListQueue< T >::is_empty(), Aleph::maps(), Aleph::DynListQueue< T >::put(), Aleph::DynList< T >::put(), Aleph::DynListQueue< T >::rear(), and Aleph::DynListQueue< T >::size().
Referenced by main().
| void demo_stack | ( | ) |
Definition at line 209 of file linear_structures_example.C.
References Aleph::DynListStack< T >::is_empty(), Aleph::maps(), Aleph::DynListStack< T >::pop(), Aleph::DynListStack< T >::push(), Aleph::DynListStack< T >::size(), and Aleph::DynListStack< T >::top().
Referenced by main().
| int main | ( | ) |
Definition at line 496 of file linear_structures_example.C.
References demo_comparison(), demo_dynarray(), demo_dynlist(), demo_queue(), demo_stack(), and Aleph::maps().