Dieser Beitrag ist alt, aber hoffentlich wird dies anderen helfen.
"Introduction to Algorithms" Buch (von Cormen, Leiserson und Rivest) ist ein gutes Buch über Algorithmen zu lesen, aber der "Pseudo-Code" ist schrecklich. Dinge wie Q [1 ... n] ist Unsinn, wenn man muss verstehen, was Q [1 ... n] ist wohl zu bedeuten. Welche müssen außerhalb des zu beachten, „Pseudo-Code.“ Darüber hinaus Bücher wie „Introduction to Algorithms“ wie eine mathematische Syntax zu verwenden, die einen Zweck von Pseudo-Code verstoßen.
Pseudo-Code sollte zwei Dinge tun. Auszug aus Syntax entfernt und leicht zu lesen. Wenn die tatsächliche Code beschreibender als der Pseudo-Code ist, und die tatsächliche Code ist mehr beschreibend, dann ist es nicht Pseudo-Code.
Angenommen, Sie waren ein einfaches Programm zu schreiben.
Screen-Design:
Welcome to the Consumer Discount Program!
Please enter the customers subtotal: 9999.99
The customer receives a 10 percent discount
The customer receives a 20 percent discount
The customer does not receive a discount
The customer's total is: 9999.99
Variablenliste:
TOTAL: double
SUB_TOTAL: double
DISCOUNT: double
Pseudo-Code:
DISCOUNT_PROGRAM
Print "Welcome to the Consumer Discount Program!"
Print "Please enter the customers subtotal:"
Input SUB_TOTAL
Select the case for SUB_TOTAL
SUB_TOTAL > 10000 AND SUB_TOTAL <= 50000
DISCOUNT = 0.1
Print "The customer receives a 10 percent discount"
SUB_TOTAL > 50000
DISCOUNT = 0.2
Print "The customer receives a 20 percent discount"
Otherwise
DISCOUNT = 0
Print "The customer does not a receive a discount"
TOTAL = SUB_TOTAL - (SUB_TOTAL * DISCOUNT)
Print "The customer's total is:", TOTAL
Beachten Sie, dass diese sehr leicht zu lesen und Referenz keine Syntax. Dies unterstützt alle drei Bohm und Jacopini der Kontrollstrukturen.
Sequenz:
Print "Some stuff"
VALUE = 2 + 1
SOME_FUNCTION(SOME_VARIABLE)
Auswahl:
if condition
Do one extra thing
if condition
do one extra thing
else
do one extra thing
if condition
do one extra thing
else if condition
do one extra thing
else
do one extra thing
Select the case for SYSTEM_NAME
condition 1
statement 1
condition 2
statement 2
condition 3
statement 3
otherwise
statement 4
Wiederholung:
while condition
do stuff
for SOME_VALUE TO ANOTHER_VALUE
do stuff
Vergleichen , die zu diesem N-Queens "Pseudo-Code" ( https://en.wikipedia.org/wiki/Eight_queens_puzzle ):
PlaceQueens(Q[1 .. n],r)
if r = n + 1
print Q
else
for j ← 1 to n
legal ← True
for i ← 1 to r − 1
if (Q[i] = j) or (Q[i] = j + r − i) or (Q[i] = j − r + i)
legal ← False
if legal
Q[r] ← j
PlaceQueens(Q[1 .. n],r + 1)
Wenn Sie es einfach nicht erklären kann, verstehen Sie es nicht gut genug. - Albert Einstein