📄 page40.html
字号:
<HTML><HEAD><TITLE>Array Subscripting Operations</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html1670" HREF="page41.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html1668" HREF="page37.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html1662" HREF="page39.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html1672" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION002130000000000000000">Array Subscripting Operations</A></H2><P>We now address the question of accessing the elements of an array of data.In general, you can think of the elements of a one-dimensional arrayas being stored in consecutive memory locations.Therefore, given the address of the first element of the array,a simple addition suffices to determine the address of an arbitraryelement of the array:<P><BLOCKQUOTE> <b>Axiom</b><A NAME="axiomv"> </A>The time required for the <em>address calculation</em> implied by anarray subscripting operation, e.g., <tt>a[i]</tt>,is a constant, <IMG WIDTH=18 HEIGHT=14 ALIGN=MIDDLE ALT="tex2html_wrap_inline57695" SRC="img31.gif" >.This time does not include the time to compute the subscript expression,nor does it include the time to access the array element.</BLOCKQUOTE><P>By applying Axiom <A HREF="page40.html#axiomv"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,we can determine that the running time for the statement<PRE>y = a[i]</PRE>is <IMG WIDTH=135 HEIGHT=21 ALIGN=MIDDLE ALT="tex2html_wrap_inline57697" SRC="img32.gif" >.Three operand fetches are required:the first to fetch the identity of the array object <tt>a</tt>;the second to fetch the identity of the index object <tt>i</tt>; and,the third to fetch the identity of the array element <tt>a[i]</tt>.<P><HR><A NAME="tex2html1670" HREF="page41.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html1668" HREF="page37.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html1662" HREF="page39.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html1672" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright © 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -