इस पोस्ट में पुराना है, लेकिन उम्मीद है कि इस दूसरों की मदद करेगा।
"परिचय एल्गोरिदम करने के लिए" पुस्तक (Cormen, Leiserson और रिवेस्ट द्वारा) एल्गोरिदम के बारे में पढ़ने के लिए एक अच्छी किताब है, लेकिन "छद्म कोड" भयानक है। क्यू [1 ... n] जैसी चीजें बकवास जब एक को समझने के लिए क्यू क्या [1 ... n] लगता है मतलब की जरूरत है। जिनमें से बाहर ध्यान दिया जाना पड़ेगा "छद्म कोड।" इसके अलावा, "एल्गोरिथम का परिचय" की तरह किताबें एक गणितीय वाक्य रचना है, जो छद्म कोड में से एक उद्देश्य उल्लंघन कर रहा है का उपयोग करना चाहते।
छद्म कोड दो काम करने चाहिए। सार वाक्य रचना से दूर और पढ़ने में आसान हो। यदि वास्तविक कोड छद्म कोड की तुलना में अधिक वर्णनात्मक है, और वास्तविक कोड और वर्णनात्मक है, तो यह छद्म कोड नहीं है।
यदि आप एक साधारण प्रोग्राम लिख रहे थे कहो।
स्क्रीन डिजाइन:
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
चर सूची:
TOTAL: double
SUB_TOTAL: double
DISCOUNT: double
छद्म कोड:
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
ध्यान दें कि यह पढ़ने के लिए बहुत आसान है और किसी भी वाक्य रचना को संदर्भित नहीं करती। यह बॉम और Jacopini के नियंत्रण संरचनाओं के सभी तीन का समर्थन करता है।
अनुक्रम:
Print "Some stuff"
VALUE = 2 + 1
SOME_FUNCTION(SOME_VARIABLE)
चयन:
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
दोहराव:
while condition
do stuff
for SOME_VALUE TO ANOTHER_VALUE
do stuff
इस एन क्वींस "छद्म कोड" (करने के लिए है कि तुलना 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)
आप यह बस व्याख्या नहीं कर सकते हैं, तो आप यह काफी अच्छी तरह से समझ में नहीं आता। - अल्बर्ट आइंस्टीन