正在加载图片...
4 Chapter 1 Analyzing Algorithms and Problems:Principles and Examples On the downside,Java has many of the same terse,cryptic syntax features of C.The object structure may force inefficiencies in time and space.Many Java constructs require greater verbosity than other languages,such as C,for instance. Although Java has many specialized features,the algorithms presented in this book avoid most of them,in the interest of being language-independent.In fact,some steps within an algorithm may be stated in pseudocode for easier readability.This section de- scribes a small subset of Java that we use for the book,and the pseudocode conventions that we use to improve readability of the algorithms.The Java-specific Appendix A gives some additional implementation details for readers who want to get a Java program running,but these details are not pertinent to understanding the main text. 1.2.1 A Usable Subset of Java A thorough acquaintance with Java is not important to understand the algorithms in this text.This section gives a brief overview of the Java features that do appear,for those readers who wish to follow the implementation issues closely.In some cases we point out object- oriented features of Java that might be used,but which we avoid so that the text can be fairly language-independent;this is mainly for the benefit of readers who are familiar with some other object-oriented language,such as C++,but who are not completely familiar with Java.A sample Java "main program"appears in Appendix A.Many books are available for in-depth coverage of the Java language. Readers who are well acquainted with Java will undoubtedly notice many instances in which some nice Java feature could have been used.However,the concepis behind the algorithms do not require any special features,and we want these concepts to be easy to grasp and apply in a variety of languages,so we leave it to the readers,once they have grasped the concepts,to tailor the implementations to their favorite language. Readers familiar with C syntax will reoognize many similarities in Java syntax:Blocks are delimited by curly braces,and ")"square brackets,"[and"]",enclose array indexes.As in C and C++,a two-dimensional array is really a one-dimensional array whose elements are themselves one-dimensional arrays,so two pairs of square brackets are needed to access an element,.as in"matrixi]”.Operators“=".“l-",“<-”,and">=" are the keyboard versions of the mathematical relational operators“=',"≠",“s",and respectively.In pseudocode the text usually prefers the mathematical versions.Text examples use the"++"and"--"operators to increment and decrement,but never use them embedded in other expressions.There are also the operators"+='.“-=”,“*=",and“/=” adopted from C.For example, p+=q:/÷Add g to p./ y-=x:/Subtract x from y As just illusirated,comments extend from"//"to end-of-line,or from"/*""to "*/"as in C++. Function headers normally look the same in Java as in C.The function header specifies the paramerer rype signature in parentheses after the function name;it specifies the return rype before the function name.The combination of return type and parameter type signature is called the function's full type signature,or profotype.Thus
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有