C++ Mathematical Expression Toolkit (ExprTk)
release
Loading...
Searching...
No Matches
exprtk
exprtk_simple_example_12.cpp
Go to the documentation of this file.
1
/*
2
**************************************************************
3
* C++ Mathematical Expression Toolkit Library *
4
* *
5
* Simple Example 12 *
6
* Author: Arash Partow (1999-2024) *
7
* URL: https://www.partow.net/programming/exprtk/index.html *
8
* *
9
* Copyright notice: *
10
* Free use of the Mathematical Expression Toolkit Library is *
11
* permitted under the guidelines and in accordance with the *
12
* most current version of the MIT License. *
13
* https://www.opensource.org/licenses/MIT *
14
* SPDX-License-Identifier: MIT *
15
* *
16
**************************************************************
17
*/
18
19
20
#include <string>
21
22
#include "
exprtk.hpp
"
23
24
25
template
<
typename
T>
26
void
bubble_sort
()
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
}
64
65
int
main
()
66
{
67
bubble_sort<double>();
68
return
0;
69
}
exprtk::expression
Definition
exprtk.hpp:21487
exprtk::parser
Definition
exprtk.hpp:22176
exprtk::parser::compile
bool compile(const std::string &expression_string, expression< T > &expr)
Definition
exprtk.hpp:24443
exprtk::symbol_table
Definition
exprtk.hpp:19745
exprtk.hpp
bubble_sort
void bubble_sort()
Definition
exprtk_simple_example_12.cpp:26
main
int main()
Definition
exprtk_simple_example_12.cpp:65
Generated by
1.9.8