Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
69 lines (57 loc) · 2.49 KB

File metadata and controls

69 lines (57 loc) · 2.49 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
**************************************************************
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 12 *
* Author: Arash Partow (1999-2024) *
* URL: https://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *
* Free use of the Mathematical Expression Toolkit Library is *
* permitted under the guidelines and in accordance with the *
* most current version of the MIT License. *
* https://www.opensource.org/licenses/MIT *
* SPDX-License-Identifier: MIT *
* *
**************************************************************
*/
#include <string>
#include "exprtk.hpp"
template <typename T>
void bubble_sort()
{
typedef exprtk::symbol_table<T> symbol_table_t;
typedef exprtk::expression<T> expression_t;
typedef exprtk::parser<T> parser_t;
const std::string bubblesort_program =
" var upper_bound := v[]; "
" "
" repeat "
" var new_upper_bound := 0; "
" "
" for (var i := 1; i < upper_bound; i += 1) "
" { "
" if (v[i - 1] > v[i]) "
" { "
" v[i - 1] <=> v[i]; "
" new_upper_bound := i; "
" }; "
" }; "
" "
" upper_bound := new_upper_bound; "
" "
" until (upper_bound <= 1); ";
T v[] = { T(9.1), T(2.2), T(1.3), T(5.4), T(7.5), T(4.6), T(3.7) };
symbol_table_t symbol_table;
symbol_table.add_vector("v",v);
expression_t expression;
expression.register_symbol_table(symbol_table);
parser_t parser;
parser.compile(bubblesort_program,expression);
expression.value();
}
int main()
{
bubble_sort<double>();
return 0;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.