C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
Functions
exprtk_simple_example_12.cpp File Reference
#include <string>
#include "exprtk.hpp"
Include dependency graph for exprtk_simple_example_12.cpp:

Go to the source code of this file.

Functions

template<typename T >
void bubble_sort ()
 
int main ()
 

Function Documentation

◆ bubble_sort()

template<typename T >
void bubble_sort ( )

Definition at line 26 of file exprtk_simple_example_12.cpp.

27{
28 typedef exprtk::symbol_table<T> symbol_table_t;
29 typedef exprtk::expression<T> expression_t;
30 typedef exprtk::parser<T> parser_t;
31
32 const std::string bubblesort_program =
33 " var upper_bound := v[]; "
34 " "
35 " repeat "
36 " var new_upper_bound := 0; "
37 " "
38 " for (var i := 1; i < upper_bound; i += 1) "
39 " { "
40 " if (v[i - 1] > v[i]) "
41 " { "
42 " v[i - 1] <=> v[i]; "
43 " new_upper_bound := i; "
44 " }; "
45 " }; "
46 " "
47 " upper_bound := new_upper_bound; "
48 " "
49 " until (upper_bound <= 1); ";
50
51 T v[] = { T(9.1), T(2.2), T(1.3), T(5.4), T(7.5), T(4.6), T(3.7) };
52
53 symbol_table_t symbol_table;
54 symbol_table.add_vector("v",v);
55
56 expression_t expression;
57 expression.register_symbol_table(symbol_table);
58
59 parser_t parser;
60 parser.compile(bubblesort_program,expression);
61
62 expression.value();
63}
bool compile(const std::string &expression_string, expression< T > &expr)
Definition exprtk.hpp:24443

References exprtk::parser< T >::compile().

Here is the call graph for this function:

◆ main()

int main ( )

Definition at line 65 of file exprtk_simple_example_12.cpp.

66{
67 bubble_sort<double>();
68 return 0;
69}