Bu mesaj eskidir, ama umarım bu başkalarına yardım edecektir.
(Cormen, Leiserson ve Rivest tarafından) "Giriş algoritmalar" kitabı algoritmaları hakkında bilgi almak için iyi bir kitap, ama "sözde kod" korkunç. bir Q varsayalım [1 ... n] demek ne anlama gerektiğinde Q [1 ... n] gibi şeyler saçmalıktır. Hangi dışında kaydetti gerekecektir "sözde kod." Dahası, "Algoritmalar Giriş" gibi kitaplar sözde kod tek bir amacı ihlal eden bir matematiksel sözdizimi, kullanmak ister.
Sözde kod iki şey yapmalıdır. uzakta sözdiziminden Özet ve okunması kolay olacak. gerçek kod sözde kodundan daha açıklayıcı olduğunu ve gerçek kod daha açıklayıcı değilse, o zaman sözde kodu değil.
Basit bir program yazıyorduk söyle.
Ekran tasarımı:
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
Değişken listesi:
TOTAL: double
SUB_TOTAL: double
DISCOUNT: double
Sözde kod:
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
Bu okumak çok kolaydır ve herhangi bir sözdizimi başvuru yapmıyor dikkat edin. Bu Bohm'un ve Jacopini kontrol yapılarının her üç destekler.
Sıra:
Print "Some stuff"
VALUE = 2 + 1
SOME_FUNCTION(SOME_VARIABLE)
Seçim:
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
Tekrarlama:
while condition
do stuff
for SOME_VALUE TO ANOTHER_VALUE
do stuff
Bu işlemin, N-kraliçe "sözde kodu" (bu karşılaştırma 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)
Basit şekilde izah edemez, bunu yeterince iyi anlamıyorum. - Albert Einstein