Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % hello world program
- -module(helloworld).
- -export([start/0]).
- -export([odwrocenieDzialania/1]).
- -export([wczytajCiagDoListy/1]).
- -export([czyJestNaLiscie/2]).
- -export([pobierzElementZListy/2]).
- -import(lists,[reverse/1]).
- -import(lists,[foreach/2]).
- -import(lists,[nth/2]).
- -import(lists,[member/2]).
- start() ->
- %wczytanie ciągu
- Ciag=wczytajCiagDoListy("a + b"),
- %odwrócenie kolejności w ciągu
- OdwroconyCiag=odwrocenieDzialania(Ciag),
- io:fwrite("~p~n",[OdwroconyCiag]),
- %utworzenie listy operatorów + - * /
- Operatory=["+","-","*","/"],
- %pobranie Elementu z listy i sprawdzenie czy jest Operatorem
- %Jeśli jest operatorem to dodaj na Stos, jeżeli nie dodaj
- %do ciągu wyjściowego
- foreach(fun(X) ->
- io:format("~p~n",[X]),
- V1=[czyJestNaLiscie(X,Operatory)],
- io:format("~p~n",V1) ,
- Stos=[],
- if
- V1 == 1 ->
- Stos=X;
- true->
- CiagWyjsciowy=[X]
- end,
- io:fwrite("~p~n",[Stos])
- end, OdwroconyCiag)
- .
- wczytajCiagDoListy(Ciag)->
- Lista=string:tokens(Ciag, " "),
- Lista.
- odwrocenieDzialania(L) ->
- reverse(L).
- pobierzElementZListy(POZYCJA,LISTA) ->
- nth(POZYCJA,LISTA).
- czyJestNaLiscie(CO,GDZIE) ->
- member(CO,GDZIE).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement