伪代码示例
Pseudo code example
总的来说,我是编程新手,我正在尝试学习它的基础知识。有人可以向我解释伪代码的概念吗?我已经做了一些研究,但额外的帮助会很棒。例如,制作花生酱和果冻三明治的伪代码会是什么样子?
-谢谢。
伪代码旨在以一种易于理解的方式描述和描述程序或算法的流程、结构和逻辑语句(在大多数情况下只是其中的一部分),而无需分析实际代码,没有任何编程知识的人也可以理解。
伪代码可以包含真实的类似代码的示例,也可以只是纯文本。
制作 PBJ 的伪代码示例如下所示:
MakePBJRoutine(input: peanut butter, jelly, bottom bread, top bread)
Begin routine:
Take bottom bread.
Spread peanut butter on bottom bread.
Spread jelly on bottom bread.
If want more jelly:
Spread jelly on bottom bread.
Place top bread slice on bottom bread
Return finished sandwich
End routine
同时,它也可以是这样的。
makePBJroutine(input: P, J, TB, BB; Out: PBJ) {
BB <- P;
BB <- J;
If(BB.J < PreferredJellyAmountConstant){
BB <- J;
}
PBJ <- (BB <- TB);
Return PBJ;
}
总的来说,我是编程新手,我正在尝试学习它的基础知识。有人可以向我解释伪代码的概念吗?我已经做了一些研究,但额外的帮助会很棒。例如,制作花生酱和果冻三明治的伪代码会是什么样子?
-谢谢。
伪代码旨在以一种易于理解的方式描述和描述程序或算法的流程、结构和逻辑语句(在大多数情况下只是其中的一部分),而无需分析实际代码,没有任何编程知识的人也可以理解。
伪代码可以包含真实的类似代码的示例,也可以只是纯文本。
制作 PBJ 的伪代码示例如下所示:
MakePBJRoutine(input: peanut butter, jelly, bottom bread, top bread)
Begin routine:
Take bottom bread.
Spread peanut butter on bottom bread.
Spread jelly on bottom bread.
If want more jelly:
Spread jelly on bottom bread.
Place top bread slice on bottom bread
Return finished sandwich
End routine
同时,它也可以是这样的。
makePBJroutine(input: P, J, TB, BB; Out: PBJ) {
BB <- P;
BB <- J;
If(BB.J < PreferredJellyAmountConstant){
BB <- J;
}
PBJ <- (BB <- TB);
Return PBJ;
}