⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slide0036.htm

📁 数据结构(java描述)课件(第二讲:线性结构)
💻 HTM
📖 第 1 页 / 共 2 页
字号:
 src="slide0036_image019.gif" alt="文本框: 自定义的向量类初步设计" style='position:absolute;
 top:5.5%;left:2.05%;width:8.42%;height:87.5%'><![endif]>
 <div v:shape="_x0000_s44036" class=O style='mso-line-spacing:"100 50 0";
 position:absolute;top:41.5%;left:-22.65%;width:64.98%;height:7.0%;visibility:
 hidden'><span lang=ZH-CN style='font-family:宋体;mso-fareast-font-family:宋体;
 font-size:150%;text-shadow:auto;mso-ansi-language:EN-US'><b>自定义的</b></span><span
 lang=ZH-CN style='font-family:宋体;mso-fareast-font-family:宋体;font-size:150%;
 text-shadow:auto;color:#9966FF;mso-ansi-language:EN-US'><b>向量类初步设计</b></span></div>
 <v:shape id="_x0000_s44037" type="#_x0000_t202" style='position:absolute;
  left:96pt;top:24pt;width:612pt;height:93.5pt' filled="f" fillcolor="#0cc [4]"
  stroked="f" strokecolor="white [1]">
  <v:fill color2="#33f [0]"/>
  <v:shadow color="black [2]"/>
  <v:textbox style='mso-fit-shape-to-text:t'/>
 </v:shape>
 <div v:shape="_x0000_s44037" class=O style='mso-line-spacing:"100 50 0"'><span
 style='position:absolute;top:5.5%;left:14.41%;width:99.25%;height:5.25%'><span
 lang=ZH-CN style='font-family:宋体;mso-fareast-font-family:宋体;mso-ansi-language:
 EN-US'>根据</span><span lang=EN-US style='mso-fareast-language:ZH-CN'>Java</span><span
 lang=ZH-CN style='font-family:宋体;mso-fareast-font-family:宋体;mso-ansi-language:
 EN-US'>中提供的向量类的基本特征,可以设计一个具有</span></span><span style='position:absolute;
 top:10.75%;left:14.41%;width:99.25%;height:5.25%'><span lang=ZH-CN
 style='font-family:宋体;mso-fareast-font-family:宋体;mso-ansi-language:EN-US'>类似功能的类,以便加深对于向量类的理解。</span><span
 lang=EN-US style='mso-fareast-language:ZH-CN'>Java</span><span lang=ZH-CN
 style='font-family:宋体;mso-fareast-font-family:宋体;mso-ansi-language:EN-US'>中向量</span></span><span
 style='position:absolute;top:16.0%;left:14.41%;width:83.14%;height:5.25%'><span
 lang=ZH-CN style='font-family:宋体;mso-fareast-font-family:宋体;mso-ansi-language:
 EN-US'>类</span><span lang=EN-US style='mso-fareast-language:ZH-CN'>Vector</span><span
 lang=ZH-CN style='font-family:宋体;mso-fareast-font-family:宋体;mso-ansi-language:
 EN-US'>参见</span><span lang=EN-US style='mso-fareast-language:ZH-CN'>JDK</span><span
 lang=ZH-CN style='font-family:宋体;mso-fareast-font-family:宋体;mso-ansi-language:
 EN-US'>帮助文件有关内容。</span></span></div>
 <!--[if !vml]><v:shapetype id="_x0000_t201" coordsize="21600,21600" o:spt="201"
  path="m,l,21600r21600,l21600,xe">
  <v:stroke joinstyle="miter"/>
  <v:path shadowok="f" o:extrusionok="f" strokeok="f" fillok="f" o:connecttype="rect"/>
  <o:lock v:ext="edit" shapetype="t"/>
 </v:shapetype><v:shape id="_x0000_s44038" type="#_x0000_t201" style='position:absolute;
  left:90pt;top:132pt;width:624pt;height:390pt;mso-wrap-style:none;
  v-text-anchor:middle' strokecolor="red" strokeweight="2.25pt">
  <![if gte mso 9]><v:imagedata src="slide0036_image001.wmz" o:title=""/>
  <![endif]><v:shadow color="black [2]"/>
  <o:lock v:ext="edit" text="t"/>
 </v:shape><![endif]--><![if !ppt]>
 <div style='position:absolute;top:24.5%;left:12.54%;width:86.89%;height:72.5%'><![endif]><object
  classid="CLSID:8BD21D10-EC42-11CE-9E0D-00AA006002F3" id=TextBox1
  v:shapes="_x0000_s44038" width="100%" height="100%">
  <param name=VariousPropertyBits value=2894088219>
  <param name=BackColor value=12640511>
  <param name=ScrollBars value=3>
  <param name=Size value="22013;13758">
  <param name=Value
  value="public class MyVector{&#13;&#10;	private Object[] elementData;&#13;&#10;	private int elementCount;&#13;&#10;	&#13;&#10;	public MyVector(){&#13;&#10;		this(10);&#13;&#10;	}&#13;&#10;	public MyVector(int initialCapacity){&#13;&#10;		elementData = new Object[initialCapacity];&#13;&#10;		elementCount = 0;&#13;&#10;	}&#13;&#10;	&#13;&#10;	public void add(int index,Object element){&#13;&#10;		if (index &gt;= elementCount + 1) {&#13;&#10;	    	throw new ArrayIndexOutOfBoundsException(index + &quot; &gt; &quot; + elementCount);&#13;&#10;		}&#13;&#10;		ensureCapacity(elementCount + 1);&#13;&#10;		System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);&#13;&#10;		elementData[index] = element;&#13;&#10;		elementCount++;&#13;&#10;	}&#13;&#10;	&#13;&#10;	public void add(Object element){&#13;&#10;		add(elementCount,element);&#13;&#10;	}&#13;&#10;	&#13;&#10;	public void set(int index,Object element){&#13;&#10;		if (index &gt;= elementCount) {&#13;&#10;	    	throw new ArrayIndexOutOfBoundsException(index + &quot; &gt;= &quot; + elementCount);&#13;&#10;		}&#13;&#10;		elementData[index] = element;&#13;&#10;	}&#13;&#10;	&#13;&#10;	public Object get(int index){&#13;&#10;		if (index &gt;= elementCount)&#13;&#10;	    	throw new ArrayIndexOutOfBoundsException(index);&#13;&#10;		return elementData[index];&#13;&#10;	}&#13;&#10;	&#13;&#10;	public int size(){&#13;&#10;		return elementCount;&#13;&#10;	}&#13;&#10;&#13;&#10;	public int indexOf(Object element){&#13;&#10;		if (element == null) {&#13;&#10;	    	for (int i = 0 ; i &lt; elementCount ; i++)&#13;&#10;				if (elementData[i] == null)	 return i;&#13;&#10;		} else {&#13;&#10;	    	for (int i = 0 ; i &lt; elementCount ; i++)&#13;&#10;				if (element.equals(elementData[i]))&#13;&#10;		    		return i;&#13;&#10;		}&#13;&#10;		return -1;&#13;&#10;	}&#13;&#10;&#13;&#10;	public void remove(Object obj){&#13;&#10;		int i = indexOf(obj);&#13;&#10;		if (i &gt;= 0) {&#13;&#10;	    	remove(i);	    &#13;&#10;		}&#13;&#10;	}&#13;&#10;	&#13;&#10;	&#13;&#10;	public boolean contain(Object element){&#13;&#10;		return indexOf(element) &gt;= 0;&#13;&#10;	}&#13;&#10;	private void ensureCapacity(int minCapacity){&#13;&#10;		int oldCapacity = elementData.length;&#13;&#10;		if (minCapacity &gt; oldCapacity) {&#13;&#10;	   		Object oldData[] = elementData;&#13;&#10;	    	int newCapacity = oldCapacity * 2;&#13;&#10;    	    if (newCapacity &lt; minCapacity) {&#13;&#10;					newCapacity = minCapacity;&#13;&#10;	    	}&#13;&#10;	    	elementData = new Object[newCapacity];&#13;&#10;	    	System.arraycopy(oldData, 0, elementData, 0, elementCount);&#13;&#10;		}	&#13;&#10;	}&#13;&#10;	public void remove(int index){&#13;&#10;		if (index &gt;= elementCount) {&#13;&#10;	    	throw new ArrayIndexOutOfBoundsException(index + &quot; &gt;= &quot; + elementCount);&#13;&#10;		}&#13;&#10;		else if (index &lt; 0) {&#13;&#10;	    	throw new ArrayIndexOutOfBoundsException(index);&#13;&#10;		}&#13;&#10;		int j = elementCount - index - 1;&#13;&#10;		if (j &gt; 0) {&#13;&#10;	    	System.arraycopy(elementData, index + 1, elementData, index, j);&#13;&#10;		}&#13;&#10;		elementCount--;&#13;&#10;		elementData[elementCount] = null; &#13;&#10;	}&#13;&#10;&#13;&#10;//	public void trimToSzie(){&#13;&#10;//		int oldCapacity = elementData.length;&#13;&#10;//		if (elementCount &lt; oldCapacity) {&#13;&#10;//	    	Object oldData[] = elementData;&#13;&#10;//	    	elementData = new Object[elementCount];&#13;&#10;//	    	System.arraycopy(oldData, 0, elementData, 0, elementCount);&#13;&#10;//		}&#13;&#10;//	}&#13;&#10;	&#13;&#10;//	public Object[] toArray(){&#13;&#10;//		Object[] result = new Object[elementCount];&#13;&#10;//		System.arraycopy(elementData, 0, result, 0, elementCount);&#13;&#10;//		return result;&#13;&#10;//	}&#13;&#10;/*	&#13;&#10;	public void removeAll(){&#13;&#10;		for (int i = 0; i &lt; elementCount; i++)&#13;&#10;	    	elementData[i] = null;&#13;&#10;		elementCount = 0;&#13;&#10;	}&#13;&#10;*/	&#13;&#10;&#13;&#10;	&#13;&#10;//	public static void vectorCopy(MyVector src,int possrc,MyVector dst,int posdst,int count){&#13;&#10;//		int length1 = src.size();&#13;&#10;//		int length2 = dst.size();&#13;&#10;//		if(length1 - possrc &lt; count || length2 - posdst &lt; count)&#13;&#10;//			throw new ArrayIndexOutOfBoundsException(count);&#13;&#10;//		for(int i = 0;i &lt; src.size();i ++){&#13;&#10;//		dst.add(src.get(i));	&#13;&#10;//		}&#13;&#10;//	}&#13;&#10;	&#13;&#10;//	public String toString(){&#13;&#10;//		String str=&quot;&quot;;&#13;&#10;//		for(int i = 0;i &lt; elementCount;i ++){&#13;&#10;//			str =  str + get(i).toString() + &quot; &quot;;&#13;&#10;//		}&#13;&#10;//		return str;&#13;&#10;//	}&#13;&#10;}">
  <param name=FontName value="Arial Black">
  <param name=FontHeight value=360>
  <param name=FontCharSet value=0>
  <param name=FontPitchAndFamily value=34>
  <param name=Text
  value="public class MyVector{&#13;&#10;	private Object[] elementData;&#13;&#10;	private int elementCount;&#13;&#10;	&#13;&#10;	public MyVector(){&#13;&#10;		this(10);&#13;&#10;	}&#13;&#10;	public MyVector(int initialCapacity){&#13;&#10;		elementData = new Object[initialCapacity];&#13;&#10;		elementCount = 0;&#13;&#10;	}&#13;&#10;	&#13;&#10;	public void add(int index,Object element){&#13;&#10;		if (index &gt;= elementCount + 1) {&#13;&#10;	    	throw new ArrayIndexOutOfBoundsException(index + &quot; &gt; &quot; + elementCount);&#13;&#10;		}&#13;&#10;		ensureCapacity(elementCount + 1);&#13;&#10;		System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);&#13;&#10;		elementData[index] = element;&#13;&#10;		elementCount++;&#13;&#10;	}&#13;&#10;	&#13;&#10;	public void add(Object element){&#13;&#10;		add(elementCount,element);&#13;&#10;	}&#13;&#10;	&#13;&#10;	public void set(int index,Object element){&#13;&#10;		if (index &gt;= elementCount) {&#13;&#10;	    	throw new ArrayIndexOutOfBoundsException(index + &quot; &gt;= &quot; + elementCount);&#13;&#10;		}&#13;&#10;		elementData[index] = element;&#13;&#10;	}&#13;&#10;	&#13;&#10;	public Object get(int index){&#13;&#10;		if (index &gt;= elementCount)&#13;&#10;	    	throw new ArrayIndexOutOfBoundsException(index);&#13;&#10;		return elementData[index];&#13;&#10;	}&#13;&#10;	&#13;&#10;	public int size(){&#13;&#10;		return elementCount;&#13;&#10;	}&#13;&#10;&#13;&#10;	public int indexOf(Object element){&#13;&#10;		if (element == null) {&#13;&#10;	    	for (int i = 0 ; i &lt; elementCount ; i++)&#13;&#10;				if (elementData[i] == null)	 return i;&#13;&#10;		} else {&#13;&#10;	    	for (int i = 0 ; i &lt; elementCount ; i++)&#13;&#10;				if (element.equals(elementData[i]))&#13;&#10;		    		return i;&#13;&#10;		}&#13;&#10;		return -1;&#13;&#10;	}&#13;&#10;&#13;&#10;	public void remove(Object obj){&#13;&#10;		int i = indexOf(obj);&#13;&#10;		if (i &gt;= 0) {&#13;&#10;	    	remove(i);	    &#13;&#10;		}&#13;&#10;	}&#13;&#10;	&#13;&#10;	&#13;&#10;	public boolean contain(Object element){&#13;&#10;		return indexOf(element) &gt;= 0;&#13;&#10;	}&#13;&#10;	private void ensureCapacity(int minCapacity){&#13;&#10;		int oldCapacity = elementData.length;&#13;&#10;		if (minCapacity &gt; oldCapacity) {&#13;&#10;	   		Object oldData[] = elementData;&#13;&#10;	    	int newCapacity = oldCapacity * 2;&#13;&#10;    	    if (newCapacity &lt; minCapacity) {&#13;&#10;					newCapacity = minCapacity;&#13;&#10;	    	}&#13;&#10;	    	elementData = new Object[newCapacity];&#13;&#10;	    	System.arraycopy(oldData, 0, elementData, 0, elementCount);&#13;&#10;		}	&#13;&#10;	}&#13;&#10;	public void remove(int index){&#13;&#10;		if (index &gt;= elementCount) {&#13;&#10;	    	throw new ArrayIndexOutOfBoundsException(index + &quot; &gt;= &quot; + elementCount);&#13;&#10;		}&#13;&#10;		else if (index &lt; 0) {&#13;&#10;	    	throw new ArrayIndexOutOfBoundsException(index);&#13;&#10;		}&#13;&#10;		int j = elementCount - index - 1;&#13;&#10;		if (j &gt; 0) {&#13;&#10;	    	System.arraycopy(elementData, index + 1, elementData, index, j);&#13;&#10;		}&#13;&#10;		elementCount--;&#13;&#10;		elementData[elementCount] = null; &#13;&#10;	}&#13;&#10;&#13;&#10;//	public void trimToSzie(){&#13;&#10;//		int oldCapacity = elementData.length;&#13;&#10;//		if (elementCount &lt; oldCapacity) {&#13;&#10;//	    	Object oldData[] = elementData;&#13;&#10;//	    	elementData = new Object[elementCount];&#13;&#10;//	    	System.arraycopy(oldData, 0, elementData, 0, elementCount);&#13;&#10;//		}&#13;&#10;//	}&#13;&#10;	&#13;&#10;//	public Object[] toArray(){&#13;&#10;//		Object[] result = new Object[elementCount];&#13;&#10;//		System.arraycopy(elementData, 0, result, 0, elementCount);&#13;&#10;//		return result;&#13;&#10;//	}&#13;&#10;/*	&#13;&#10;	public void removeAll(){&#13;&#10;		for (int i = 0; i &lt; elementCount; i++)&#13;&#10;	    	elementData[i] = null;&#13;&#10;		elementCount = 0;&#13;&#10;	}&#13;&#10;*/	&#13;&#10;&#13;&#10;	&#13;&#10;//	public static void vectorCopy(MyVector src,int possrc,MyVector dst,int posdst,int count){&#13;&#10;//		int length1 = src.size();&#13;&#10;//		int length2 = dst.size();&#13;&#10;//		if(length1 - possrc &lt; count || length2 - posdst &lt; count)&#13;&#10;//			throw new ArrayIndexOutOfBoundsException(count);&#13;&#10;//		for(int i = 0;i &lt; src.size();i ++){&#13;&#10;//		dst.add(src.get(i));	&#13;&#10;//		}&#13;&#10;//	}&#13;&#10;	&#13;&#10;//	public String toString(){&#13;&#10;//		String str=&quot;&quot;;&#13;&#10;//		for(int i = 0;i &lt; elementCount;i ++){&#13;&#10;//			str =  str + get(i).toString() + &quot; &quot;;&#13;&#10;//		}&#13;&#10;//		return str;&#13;&#10;//	}&#13;&#10;}">
 </object><![if !ppt]></div>
 <![endif]><p:shaperange href="master04.xml#_x0000_m5154"/><v:shape id="_x0000_s44039"
  type="#_x0000_m5154" style='position:absolute;left:90pt;top:48pt;width:612pt;
  height:90pt' o:userdrawn="f">
  <v:fill o:detectmouseclick="t"/>
  <v:stroke o:forcedash="t"/>
  <o:lock v:ext="edit" text="f"/>
  <p:placeholder type="title"/></v:shape>
 <div v:shape="_x0000_s44039" class=T><span style='position:absolute;
 top:13.75%;left:13.48%;width:83.14%;height:8.5%'><span lang=ZH-CN
 style='font-family:宋体;mso-fareast-font-family:宋体;mso-ansi-language:EN-US;
 mso-special-format:lastCR;display:none'>&#13;</span></span></div>
</p:slide></div>

</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -