Skip to content

Latest commit

 

History

History

csharp

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

二分木を使った数式の逆ポーランド記法化と計算のC#での実装。

前提条件・依存関係

.NETランタイムもしくはMonoランタイム、およびC#コンパイラが必要です。

dotnetコマンドを使用してビルド・実行する場合は、.NET SDKが必要です。

ビルドおよび実行

コマンドdotnet runを実行し、式を入力することにより、入力された式に対して逆ポーランド記法化・計算を行うことができます。

実行例:

$ dotnet run
input expression: 2 + 5 * 3 - 4
expression: 2+5*3-4
reverse polish notation: 2 5 3 * + 4 -
infix notation: ((2 + (5 * 3)) - 4)
polish notation: - + 2 * 5 3 4
calculated result: 13

その他、dotnetコマンドで以下の操作を行うことができます。

dotnet build # ソースファイルをコンパイルする
dotnet run   # ソースファイルをコンパイルして実行する
dotnet clean # 成果物ファイルを削除する

.NETランタイム/csc(Microsoft C# Compiler)を使用する場合

csc polish.cs # ソースファイルをコンパイルする
polish.exe    # コンパイルした実行可能ファイルを実行する

Monoランタイム/mcs(Mono C# Compiler)を使用する場合

mcs polish.cs   # ソースファイルをコンパイルする
mono polish.exe # コンパイルした実行可能ファイルを実行する

Monoランタイム/mcsのインストール方法

Ubuntuの場合:

sudo apt install mono-runtime mono-mcs