亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? java data structures (2nd edition).mht

?? java數(shù)據(jù)結(jié)構(gòu)與算法有很好的代碼
?? MHT
?? 第 1 頁(yè) / 共 5 頁(yè)
字號(hào):
every time an object is created using this class. The <CODE>set()</CODE> =
and=20
<CODE>get()</CODE> functions set and get the value of <CODE>'i'</CODE>=20
respectively. One useful terminology is that functions in objects are =
not called=20
functions, they're called methods. So, to refer to function =
<CODE>set()</CODE>,=20
you'd say "method <CODE>set()</CODE>." &nbsp; That's all there is to=20
objects!</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The way you declare a variable, or =
in this=20
case, an object of that class, is:</P><PRE><CODE>pSimpleObject myObject;
myObject =3D new pSimpleObject();</CODE></PRE>
<P align=3Djustify>or</P><PRE><CODE>pSimpleObject myObject =3D new =
pSimpleObject();</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The first example illustrates how =
you=20
declare an object named <CODE>myObject</CODE>, of class=20
<CODE>pSimpleObject</CODE>, and later instantiate it (a process of =
actual=20
creation, where it calls the object's constructor method). The second =
approach=20
illustrates that it all can be done in one line. The object does not get =
created=20
when you just declare it, it's only created when you do a =
<CODE>new</CODE> on=20
it.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; If you're familiar with C/C++, =
think of=20
objects as pointers. First, you declare it, and then you allocate a new =
object=20
to that pointer. The only limitation seems to be that you can't do math =
on these=20
pointers, other than that, they behave as plain and simple C/C++ =
pointers. (You=20
might want to think of objects as references however.)</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Using variables is really cool, =
and useful,=20
but sometimes we'd like to have more. Like the ability to work with =
hundreds or=20
maybe thousands of variables at the same time. And here's where our next =
section=20
starts, the Arrays!</P>
<HR SIZE=3D1>

<H2><A name=3DArrays><I>Arrays...</I></A></H2>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; One of the most basic data =
structures, is an=20
array. An array is just a number of items, of same type, stored in =
linear order,=20
one after another. Arrays have a set limit on their size, they can't =
grow beyond=20
that limit. Arrays usually tend to be easier to work with and generally =
more=20
efficient than other structural approaches to organizing data; way =
better than a=20
<EM>no formal structure</EM> approach.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; For example, lets say you wanted =
to have 100=20
numbers. You can always resort to having 100 different variables, but =
that would=20
be a pain. Instead, you can use the clean notation of an array to =
create, and=20
later manipulate those 100 numbers. For example, to create an array to =
hold 100=20
numbers you would do something like this:</P><PRE><CODE>int[] myArray;
myArray =3D new int[100];</CODE></PRE>
<P align=3Djustify>or</P><PRE><CODE>int[] myArray =3D new =
int[100];</CODE></PRE>
<P align=3Djustify>or</P><PRE><CODE>int myArray[] =3D new =
int[100];</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The three notations above do =
exactly the=20
same thing. The first declares an array, and then it creates an array by =
doing a=20
<CODE>new</CODE>. The second example shows that it can all be one in one =
line.=20
And the third example shows that Java holds the backwards compatibility =
with=20
C++, where the array declaration is: <CODE>int myArray[];</CODE> instead =
of=20
<CODE>int[] myArray;</CODE>. To us, these notations are exactly the =
same. I do=20
however prefer to use the Java one.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Working with arrays is also =
simple, think of=20
them as just a line of variables, we can address the 5th element =
(counting from=20
0, so, it's actually the 6th element) by simply doing:</P><PRE><CODE>int =
i =3D myArray[5];</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The code above will set integer=20
<CODE>'i'</CODE> to the value of the 5th (counting from 0) element of =
the array.=20
Similarly, we can set an array value. For example, to set the 50th =
element=20
(counting from 0), to the value of <CODE>'i'</CODE> we'd do something =
like:</P><PRE><CODE>myArray[50] =3D i;</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; As you can see, arrays are fairly =
simple.=20
The best and most convenient way to manipulate arrays is using loops. =
For=20
example, lets say we wanted to make an array from 1 to 100, to hold =
numbers from=20
1 to 100 respectively, and later add seven to every element inside that =
array.=20
This can be done very easily using two loops. (actually, it can be done =
in one=20
loop, but I am trying to separate the problem into =
two)</P><PRE><CODE>int i;
for(i=3D0;i&lt;100;i++)
    myArray[i] =3D i;
for(i=3D0;i&lt;100;i++)
    myArray[i] =3D myArray[i] + 7;</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; In Java, we don't need to remember =
the size=20
of the array as in C/C++. Here, we have the length variable in every =
array, and=20
we can check it's length whenever we need it. So to print out any array =
named:=20
<CODE>myArray</CODE>, we'd do something like:</P><PRE><CODE>for(int i =
=3D 0;i&lt;myArray.length;i++)
    System.out.println(myArray[i]);</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; This will work, given the objects =
inside the=20
myArray are printable, (have a corresponding <CODE>toString()</CODE> =
method), or=20
are of primitive type.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; One of the major limitations on =
arrays is=20
that they're fixed in size. They can't grow or shrink according to need. =
If you=20
have an array of 100 max elements, it will not be able to store 101 =
elements.=20
Similarly, if you have less elements, then the unused space is being =
wasted=20
(doing nothing).</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Java API provides data storage =
classes,=20
which implement an array for their storage. As an example, take the=20
<CODE>java.util.Vector</CODE> class (JDK 1.2), it can grow, shrink, and =
do some=20
quite useful things. The way it does it is by reallocating a new array =
every=20
time you want to do some of these operations, and later copying the old =
array=20
into the new array. It can be quite fast for small sizes, but when =
you're=20
talking about several megabyte arrays, and every time you'd like to add =
one more=20
number (or object) you might need to reallocate the entire array; that =
can get=20
quite slow. Later, we will look at other data structures where we won't =
be=20
overly concerned with the amount of the data and how often we need to=20
resize.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Even in simplest situations, =
arrays are=20
powerful storage constructs. Sometimes, however, we'd like to have more =
than=20
just a plain vanilla array.</P>
<HR SIZE=3D1>

<H2><A name=3DArray_Stack><I>Array Stack...</I></A></H2>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The next and more serious data =
structure=20
we'll examine is the Stack. A stack is a FILO (First In, Last Out), =
structure.=20
For now, we'll just deal with the array representation of the stack. =
Knowing=20
that we'll be using an array, we automatically think of the fact that =
our stack=20
has to have a maximum size.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; A stack has only one point where =
data enters=20
or leaves. We can't insert or remove elements into or from the middle of =
the=20
stack. As I've mentioned before, everything in Java is an object, (since =
it's an=20
Object Oriented language), so, lets write a stack =
object!</P><PRE><CODE>public class pArrayStackInt{
    protected int head[];
    protected int pointer;

    public pArrayStackInt(int capacity){
        head =3D new int[capacity];
        pointer =3D -1;
    }
    public boolean isEmpty(){
        return pointer =3D=3D -1;
    }
    public void push(int i){
        if(pointer+1 &lt; head.length)
            head[++pointer] =3D i;
    }
    public int pop(){
        if(isEmpty())
            return 0;
        return head[pointer--];
    }
}</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; As you can see, that's the stack =
class. The=20
constructor named <CODE>pArrayStackInt()</CODE> accepts an integer. That =
integer=20
is to initialize the stack to that specific size. If you later try to=20
<CODE>push()</CODE> more integers onto the stack than this capacity, it =
won't=20
work. Nothing is complete without testing, so, lets write a test driver =
class to=20
test this stack.</P><PRE><CODE>import java.io.*;
import pArrayStackInt;

class pArrayStackIntTest{
    public static void main(String[] args){
        pArrayStackInt s =3D new pArrayStackInt(10);
        int i,j;
        System.out.println("starting...");
        for(i=3D0;i&lt;10;i++){
            j =3D (int)(Math.random() * 100);
            s.push(j);
            System.out.println("push: " + j);
        }
        while(!s.isEmpty()){
            System.out.println("pop: " + s.pop());
        }
        System.out.println("Done ;-)");
    }
}</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The test driver does nothing =
special, it=20
inserts ten random numbers onto the stack, and then pops them off. =
Writing to=20
standard output exactly what it's doing. The output gotten from this =
program=20
is:</P><PRE><CODE>starting...
push: 33
push: 66
push: 10
push: 94
push: 67
push: 79
push: 48
push: 7
push: 79
push: 32
pop: 32
pop: 79
pop: 7
pop: 48
pop: 79
pop: 67
pop: 94
pop: 10
pop: 66
pop: 33
Done ;-)</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; As you can see, the first numbers =
to be=20
pushed on, are the last ones to be popped off. A perfect example of a =
FILO=20
structure. The output also assures us that the stack is working =
properly.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Now that you've had a chance to =
look at the=20
source, lets look at it more closely.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The <CODE>pArrayStackInt</CODE> =
class is=20
using an array to store it's data. The data is <CODE>int</CODE> type =
(for=20
simplicity). There is a head data member, that's the actual array. =
Because we're=20
using an array, with limited size, we need to keep track of it's size, =
so that=20
we don't overflow it; we always look at <CODE>head.length</CODE> to =
check for=20
maximum size.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The second data member is=20
<CODE>pointer</CODE>. Pointer, in here, points to the top of the stack. =
It=20
always has the position which had the last insertion, or -1 if the stack =
is=20
empty.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The constructor:=20
<CODE>pArrayStackInt()</CODE>, accepts the maximum size parameter to set =
the=20
size of the stack. The rest of the functions is just routine =
initialization.=20
Notice that pointer is initialized to -1, this makes the next position =
to be=20
filled in an array, 0.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The <CODE>isEmpty()</CODE> =
function is self=20
explanatory, it returns <CODE>true</CODE> if the stack is empty=20
(<CODE>pointer</CODE> is -1), and <CODE>false</CODE> otherwise. The =
return type=20
is <CODE>boolean</CODE>.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The <CODE>push(int)</CODE> =
function is=20
fairly easy to understand too. First, it checks to see if the next =
insertion=20
will not overflow the array. If no danger from overflow, then it =
inserts. It=20
first increments the pointer and then inserts into the new location =
pointed to=20
by the updated <CODE>pointer</CODE>. It could easily be modified to =
actually=20
make the array grow, but then the whole point of "simplicity" of using =
an array=20
will be lost.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The <CODE>int pop()</CODE> =
function is also=20
very simple. First, it checks to see if stack is not empty, if it is =
empty, it=20
will return 0. In general, this is a really bad error to pop of =
something from=20
an empty stack. You may want to do something more sensible than simply =
returning=20
a 0 (an exception throw would not be a bad choice). I did it this way =
for the=20
sake of simplicity. Then, it returns the value of the array element =
currently=20
pointed to by pointer, and it decrements the pointer. This way, it is =
ready for=20
the next <CODE>push</CODE> or <CODE>pop</CODE>.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; I guess that just about covers it. =
Stack is=20
very simple and is very basic. There are tons of useful algorithms which =
take=20
advantage of this FILO structure. Now, lets look at alternative=20
implementations...</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Given the above, a lot of the C++ =
people=20
would look at me strangely, and say: "All this trouble for a stack that =
can only=20
store integers?" Well, they're probably right for the example above. It =
is too=20
much trouble. The trick I'll illustrate next is what makes Java my =
favorite=20
Object Oriented language.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; In C, we have the =
<CODE>void*</CODE> type,=20
to make it possible to store "generic" data. In C++, we also have the=20
<CODE>void*</CODE> type, but there, we have very useful templates. =
Templates is=20
a C++ way to make generic objects, (objects that can be used with any =
type).=20
This makes quite a lot of sense for a data storage class; why should we =
care=20
what we're storing?</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The way Java implements these =
kinds of=20
generic classes is by the use of parent classes. In Java, every object =
is a=20
descendent of the <CODE>Object</CODE> class. So, we can just use the=20
<CODE>Object</CODE> class in all of our structures, and later cast it to =
an=20
appropriate type. Next, we'll write an example that uses this technique =
inside a=20
generic stack.</P><PRE><CODE>public class pArrayStackObject{

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品视频一区| 欧美tk—视频vk| 日韩av中文在线观看| 欧美精品一区二区三区蜜桃| 国产黄色精品网站| 亚洲精品伦理在线| 久久久久久久久久久久电影| 91丨九色porny丨蝌蚪| 蜜桃传媒麻豆第一区在线观看| 欧美经典三级视频一区二区三区| 91视频在线看| 国产一区 二区| 美女一区二区视频| 欧美国产丝袜视频| 欧美日韩综合在线免费观看| 国产一区二区毛片| 日韩有码一区二区三区| 亚洲免费观看高清完整版在线观看熊| 欧美xxxxx牲另类人与| 欧美亚洲综合一区| 色综合久久久久| 精品一区二区三区蜜桃| 国产精品一二三四| 老司机午夜精品| 美女在线一区二区| 午夜精品久久久久久久| 亚洲精品国产第一综合99久久 | 中文字幕va一区二区三区| 在线视频国内一区二区| 久久爱www久久做| 亚洲成人动漫av| 奇米888四色在线精品| 天堂蜜桃91精品| 精品一区二区精品| 激情综合网天天干| 成人一道本在线| 激情五月婷婷综合网| 免费av成人在线| 国产iv一区二区三区| 91性感美女视频| 欧美精品精品一区| 日韩欧美一区在线观看| 久久精品一区二区| 亚洲三级电影网站| 一本久道中文字幕精品亚洲嫩| 九九**精品视频免费播放| 国产成人免费视频一区| 91色|porny| 精品乱人伦小说| 亚洲国产综合色| 国产成人精品www牛牛影视| 91在线精品秘密一区二区| 欧美日韩国产高清一区二区三区 | 99久久免费视频.com| 欧美三级电影网| 亚洲成人免费影院| 国产不卡在线一区| 欧美久久久一区| 亚洲一二三区视频在线观看| 国产一区美女在线| 91 com成人网| 一区二区三区四区在线| 国产suv精品一区二区883| 91精品视频网| 天天色天天操综合| 欧美色偷偷大香| 亚洲一区在线观看视频| 99久久er热在这里只有精品66| 久久久久久一二三区| 日本不卡视频在线观看| 欧美日高清视频| 一区二区三区日本| 一本到一区二区三区| 亚洲精品免费视频| 在线欧美一区二区| 性做久久久久久免费观看欧美| 日本韩国精品在线| 亚洲激情图片qvod| 日本伦理一区二区| 五月激情丁香一区二区三区| 欧美精品123区| 日本不卡一区二区| 亚洲精品一区二区三区蜜桃下载| 美腿丝袜一区二区三区| 555www色欧美视频| 亚洲成人一二三| 欧美自拍偷拍午夜视频| 亚洲图片一区二区| 日韩精品一区二区三区老鸭窝 | 亚洲视频香蕉人妖| 色国产综合视频| 另类专区欧美蜜桃臀第一页| 日本一区二区三区在线不卡| 成人亚洲一区二区一| 91亚洲永久精品| 日本网站在线观看一区二区三区 | 国产精品久久久久久亚洲伦| 在线区一区二视频| 高清久久久久久| 日韩精品91亚洲二区在线观看| 国产精品久久久久久久久免费桃花| 欧美精品第1页| 日本高清不卡在线观看| 波多野结衣视频一区| 国产乱子轮精品视频| 亚洲成人福利片| 亚洲国产精品一区二区久久| 国产精品国产三级国产aⅴ无密码| 日韩欧美国产一二三区| 欧美三级视频在线播放| 色婷婷av一区二区三区之一色屋| 国产精品538一区二区在线| 日韩国产欧美三级| 日韩电影免费在线看| 图片区小说区区亚洲影院| 伊人性伊人情综合网| 一区二区三区小说| 一卡二卡欧美日韩| 亚洲精品久久久蜜桃| 综合久久综合久久| 亚洲午夜久久久久久久久久久| 亚洲三级小视频| 一区二区欧美精品| 日韩va亚洲va欧美va久久| 精品一区二区av| 国产91清纯白嫩初高中在线观看| 国产91对白在线观看九色| 成人app在线| 色菇凉天天综合网| 日韩丝袜情趣美女图片| 日韩亚洲欧美在线| 久久综合色8888| 亚洲欧洲韩国日本视频| 亚洲v中文字幕| 国产资源精品在线观看| 色诱视频网站一区| 亚洲欧美日韩成人高清在线一区| 亚洲综合区在线| 国产一区视频网站| 在线免费观看不卡av| 久久久久综合网| 亚洲综合一二三区| 国产精品1024| 欧美喷水一区二区| 国产精品国产三级国产aⅴ入口 | 成人av资源在线| 欧美电影在线免费观看| 国产精品夫妻自拍| 蜜桃在线一区二区三区| 色综合天天综合给合国产| 日韩精品综合一本久道在线视频| 国产精品久久99| 国产精品一区二区男女羞羞无遮挡 | 精品美女一区二区三区| 一区二区三区四区视频精品免费| 精品一区二区在线免费观看| 欧美色图12p| 艳妇臀荡乳欲伦亚洲一区| 成人综合在线观看| 久久久精品天堂| 麻豆高清免费国产一区| 91精品国产福利| 天天av天天翘天天综合网| 成人晚上爱看视频| 久久成人久久爱| 欧美专区日韩专区| 亚洲特级片在线| 91日韩一区二区三区| 欧美国产日韩亚洲一区| 岛国精品在线观看| 国产精品久久久久婷婷| 成人精品一区二区三区四区 | 91精品国产色综合久久不卡电影 | 91精品国产高清一区二区三区蜜臀| 一区二区三区中文字幕电影| 成人av电影免费观看| 久久精品国产99| 日韩午夜电影av| 黑人巨大精品欧美一区| 久久久99精品久久| 成人短视频下载| 中文字幕佐山爱一区二区免费| 色综合天天综合在线视频| 亚洲午夜在线观看视频在线| 欧美人与禽zozo性伦| 精品一区二区免费在线观看| 久久嫩草精品久久久精品一| www.成人网.com| 日日夜夜精品视频天天综合网| 欧美v亚洲v综合ⅴ国产v| av资源网一区| 日韩在线一二三区| 中文字幕在线观看不卡| 欧美三级电影在线看| 狠狠色丁香久久婷婷综| 亚洲乱码国产乱码精品精的特点| 欧美日韩国产天堂| 99re热视频这里只精品 | 青青国产91久久久久久| 国产精品色在线观看|