【发布时间】:2020-11-19 14:58:57
【问题描述】:
我目前正在处理这个类分配,即在 Erlang 中创建一个 btree 并创建一个能够删除其上的元素的函数。从我的角度来看,我无法理解 Erlang 在尝试编译我的代码时返回给我的错误。
btree.erl:211: syntax error before: 'end'
据我所知,哪个不是真的,但我一定是错的?我怀疑它位于嵌套 if 子句中,但我尝试根据此处 Nested If Clause 编写嵌套 if 语句。
我怀疑这可能只是一个小问题,我现在压力太大/盲目看不到。任何帮助将不胜感激。
deleteBT(BTree = {ElementAtom,Height,Links,Rechts}, Element) ->
if
Element > ElementAtom ->
NeuRechts = deleteBT(Rechts, Element),
Hanoi = findHeight(NeuRechts, Links),
{ElementAtom,Hanoi,Links,NeuRechts};
Element < ElementAtom ->
NeuLinks = deleteBT(Links, Element),
Hanoi = findHeight(NeuLinks, Rechts),
{ElementAtom,Hanoi,NeuLinks,Rechts};
Element == ElementAtom ->
if
BTree == {ElementAtom, Height, Links,{}} -> Links;
BTree == {ElementAtom, Height, {},Rechts} -> Rechts;
BTree == {ElementAtom, Height, {},{}} -> {};
BTree == {ElementAtom, Height, Links,Rechts} ->
Kleinster = kLZahl(Rechts), %Findet uns die Kleinste Zahl vom übergebenen Baum
RechtsNeu = deleteBT(Rechts, Kleinster),
Hanoi = findHeight(RechtsNeu, Links),
{Kleinster, Hanoi, Links, RechtsNeu};
true -> -1
end;
true -> -1;
end.
【问题讨论】:
-
我找到了解决方案,我在最后一个真条件上删除了一个分号。
-
end之前的最后一个表达式不能有; -
谢谢你,何塞,我也刚刚得到了同样的认识。
标签: erlang