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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

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

?? java數(shù)據(jù)結(jié)構(gòu)與算法有很好的代碼
?? MHT
?? 第 1 頁 / 共 5 頁
字號:
    protected Object head[];
    protected int pointer;

    public pArrayStackObject(int capacity){
        head =3D new Object[capacity];
        pointer =3D -1;
    }
    public boolean isEmpty(){
        return pointer =3D=3D -1;
    }
    public void push(Object i){
        if(pointer+1 < head.length)
            head[++pointer] =3D i;
    }
    public Object pop(){
        if(isEmpty())
            return null;
        return head[pointer--];
    }
}</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The above is very similar to the=20
<CODE>int</CODE> only version, the only things that changed are the=20
<CODE>int</CODE> to <CODE>Object</CODE>. This stack, allows the=20
<CODE>push()</CODE> and <CODE>pop()</CODE> of any <CODE>Object</CODE>. =
Lets=20
convert our old test driver to accommodate this new stack. The new test =
module=20
will be inserting <CODE>java.lang.Integer</CODE> objects (not =
<CODE>int</CODE>;=20
not primitive type).</P><PRE><CODE>import java.io.*;
import pArrayStackObject;

class pArrayStackObjectTest{
    public static void main(String[] args){
        pArrayStackObject s =3D new pArrayStackObject(10);
        Integer j =3D null;
        int i;
        System.out.println("starting...");
        for(i=3D0;i&lt;10;i++){
            j =3D new Integer((int)(Math.random() * 100));
            s.push(j);
            System.out.println("push: " + j);
        }
        while(!s.isEmpty()){
            System.out.println("pop: " + ((Integer)s.pop()));
        }
        System.out.println("Done ;-)");
    }
}</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; And for the sake of being =
complete, I'll=20
include the output. Notice that here, we're not inserting elements of=20
<CODE>int</CODE> type, we're inserting elements of=20
<CODE>java.lang.Integer</CODE> type. This means, that we can insert any=20
<CODE>Object</CODE>.</P><PRE><CODE>starting...
push: 45
push: 7
push: 33
push: 95
push: 28
push: 98
push: 87
push: 99
push: 66
push: 40
pop: 40
pop: 66
pop: 99
pop: 87
pop: 98
pop: 28
pop: 95
pop: 33
pop: 7
pop: 45
Done ;-)</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; I guess that covers stacks. The =
main idea=20
you should learn from this section is that a stack is a FILO data =
structure.=20
After this section, non of the data structures will be working with =
primitive=20
types, and everything will be done solely with objects. (now that you =
know how=20
it's done...)</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; And now, onto the array relative =
of Stack,=20
the Queue.</P>
<HR SIZE=3D1>

<H2><A name=3DArray_Queue><I>Array Queues...</I></A></H2>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; A queue is a FIFO (First In, First =
Out)=20
structure. Anything that's inserted first, will be the first to leave =
(kind of=20
like the real world queues.) This is totally the opposite of what a =
stack is.=20
Although that is true, the queue implementation is quite similar to the =
stack=20
one. It also involves pointers to specific places inside the array.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; With a queue, we need to maintain =
two=20
pointers, the <CODE>start</CODE> and the <CODE>end</CODE>. We'll =
determine when=20
the queue is empty if <CODE>start</CODE> and <CODE>end</CODE> point to =
the same=20
element. To determine if the queue is full (since it's an array), we'll =
have a=20
<CODE>boolean</CODE> variable named <CODE>full</CODE>. To insert, we'll =
add one=20
to the <CODE>start</CODE>, and mod (the <CODE>%</CODE> operator) with =
the size=20
of the array. To remove, we'll add one to the <CODE>end</CODE>, and mod =
(the=20
<CODE>%</CODE> operator) with the size of the array. Simple? Well, lets =
write=20
it.</P><PRE><CODE>public class pArrayQueue{
    protected Object[] array;
    protected int start,end;
    protected boolean full;

    public pArrayQueue(int maxsize){
        array =3D new Object[maxsize];
        start =3D end =3D 0;
        full =3D false;
    }

    public boolean isEmpty(){
        return ((start =3D=3D end) &amp;&amp; !full);
    }

    public void insert(Object o){
        if(!full)
            array[start =3D (++start % array.length)] =3D o;
        if(start =3D=3D end)
            full =3D true;
    }

    public Object remove(){
        if(full)
            full =3D false;
        else if(isEmpty())
            return null;
        return array[end =3D (++end % array.length)];
    }
}</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Well, that's the queue class. In =
it, we have=20
four variables, the <CODE>array</CODE>, the <CODE>start</CODE> and=20
<CODE>end</CODE>, and a <CODE>boolean full</CODE>. The constructor=20
<CODE>pArrayQueue(int maxsize)</CODE> initializes the queue, and =
allocates an=20
<CODE>array</CODE> for data storage. The <CODE>isEmpty()</CODE> method =
is self=20
explanatory, it checks to see if <CODE>start</CODE> and <CODE>end</CODE> =
are=20
equal; this can only be in two situations: when the queue is empty, and =
when the=20
queue is full. It later checks the <CODE>full</CODE> variable and =
returns=20
whether this queue is empty or not.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The <CODE>insert(Object)</CODE> =
method,=20
accepts an <CODE>Object</CODE> as a parameter, checks whether the queue =
is not=20
<CODE>full</CODE>, and inserts it. The insert works by adding one to=20
<CODE>start</CODE>, and doing a mod with <CODE>array.length</CODE> (the =
size of=20
the <CODE>array</CODE>), the resulting location is set to the incoming =
object.=20
We later check to see if this insertion caused the queue to become full, =
if yes,=20
we note this by setting the <CODE>full</CODE> variable to =
<CODE>true</CODE>.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The <CODE>Object remove()</CODE> =
method,=20
doesn't accept any parameters, and returns an <CODE>Object</CODE>. It =
first=20
checks to see if the queue is <CODE>full</CODE>, if it is, it sets=20
<CODE>full</CODE> to <CODE>false</CODE> (since it will not be =
<CODE>full</CODE>=20
after this removal). If it's not <CODE>full</CODE>, it checks if the =
queue is=20
empty, by calling <CODE>isEmpty()</CODE>. If it is, the method returns a =

<CODE>null</CODE>, indicating that there's been an error. This is =
usually a=20
pretty bad bug inside a program, for it to try to remove something from =
an empty=20
queue, so, you might want to do something more drastic in such a =
situation (like=20
an exception throw). The method continues by removing the end object =
from the=20
queue. The removal is done in the same way insertion was done. By adding =
one to=20
the <CODE>end</CODE>, and later mod it with <CODE>array.length</CODE>=20
(<CODE>array</CODE> size), and that position is returned.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; There are other implementations of =
the same=20
thing, a little re-arrangement can make several <CODE>if()</CODE> =
statements=20
disappear. The reason it's like this is because it's pretty easy to =
think of it.=20
Upon insertion, you add one to <CODE>start</CODE> and mod, and upon =
removal, you=20
add one to <CODE>end</CODE> and mod... easy?</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Well, now that we know how it =
works, lets=20
actually test it! I've modified that pretty cool test driver from the =
stack=20
example, and got it ready for this queue, so, here it =
comes:</P><PRE><CODE>import java.io.*;
import pArrayQueue;

class pArrayQueueTest{
    public static void main(String[] args){
        pArrayQueue q =3D new pArrayQueue(10);
        Integer j =3D null;
        int i;
        System.out.println("starting...");
        for(i=3D0;i&lt;10;i++){
            j =3D new Integer((int)(Math.random() * 100));
            q.insert(j);
            System.out.println("insert: " + j);
        }
        while(!q.isEmpty()){
            System.out.println("remove: " + ((Integer)q.remove()));
        }
        System.out.println("Done ;-)");
    }
}</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; As you can see, it inserts ten =
random=20
<CODE>java.lang.Integer Objects</CODE> onto the queue, and later prints =
them=20
out. The output from the program follows:</P><PRE><CODE>starting...
insert: 3
insert: 70
insert: 5
insert: 17
insert: 26
insert: 79
insert: 12
insert: 44
insert: 25
insert: 27
remove: 3
remove: 70
remove: 5
remove: 17
remove: 26
remove: 79
remove: 12
remove: 44
remove: 25
remove: 27
Done ;-)</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; I suggest you compare this output =
to the one=20
from stack. It's almost completely different. I guess that's it for this =
array=20
implementation of this FIFO data structure. And now, onto something more =

complex...</P>
<HR SIZE=3D1>

<H2><A name=3DArray_List><I>Array Lists...</I></A></H2>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The next step up in complexity is =
a list.=20
Most people prefer to implement a list as a linked list (and I'll show =
how to do=20
that later), but what most people miss, is that lists can also be =
implemented=20
using arrays. A list has no particular structure; it just has to allow =
for the=20
insertion and removal of objects from both ends, and some way of looking =
at the=20
middle elements.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; A list is kind of a stack combined =
with a=20
queue; with additional feature of looking at the middle elements. =
Preferably, a=20
list should also contain the current number of elements. Well, lets not =
just=20
talk about a list, but write one!</P><PRE><CODE>public class pArrayList{
    protected Object[] array;
    protected int start,end,number;

    public pArrayList(int maxsize){
        array =3D new Object[maxsize];
        start =3D end =3D number =3D 0;
    }
    public boolean isEmpty(){
        return number =3D=3D 0;
    }
    public boolean isFull(){
        return number &gt;=3D array.length;
    }
    public int size(){
        return number;
    }
    public void insert(Object o){
        if(number &lt; array.length){
            array[start =3D (++start % array.length)] =3D o;
            number++;
        }
    }
    public void insertEnd(Object o){
        if(number &lt; array.length){
            array[end] =3D o;
            end =3D (--end + array.length) % array.length;
            number++;
        }
    }
    public Object remove(){
        if(isEmpty())
            return null;
        number--;
        int i =3D start;
        start =3D (--start + array.length) % array.length;
        return array[i];
    }
    public Object removeEnd(){
        if(isEmpty())
            return null;
        number--;
        return array[end =3D (++end % array.length)];
    }
    public Object peek(int n){
        if(n &gt;=3D number)
            return null;
        return array[(end + 1 + n) % array.length];
    }
}</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The class contains four data =
elements:=20
<CODE>array</CODE>, <CODE>start</CODE>, <CODE>end</CODE>, and=20
<CODE>number</CODE>. The <CODE>number</CODE> is the number of elements =
inside=20
the array. The <CODE>start</CODE> is the starting pointer, and the=20
<CODE>end</CODE> is the ending pointer inside the <CODE>array</CODE> =
(kind of=20
like the queue design).</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The constructor, =
<CODE>pArrayList()</CODE>,=20
and methods <CODE>isEmpty()</CODE>, <CODE>isFull()</CODE>, and=20
<CODE>size()</CODE>, are pretty much self explanatory. The =
<CODE>insert()</CODE>=20
method works exactly the same way as an equivalent queue method. It just =

increments the <CODE>start</CODE> pointer, does a mod (the =
<CODE>%</CODE>=20
symbol), and inserts into the resulting position.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The <CODE>insertEnd(Object)</CODE> =
method,=20
first checks that there is enough space inside the <CODE>array</CODE>. =
It then=20
inserts the element into the <CODE>end</CODE> location. The next trick =
is to=20

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本色综合中文字幕| 夜夜嗨av一区二区三区中文字幕| 欧美亚洲自拍偷拍| 欧美精品日韩综合在线| 欧美日韩免费一区二区三区视频| 欧美性受xxxx黑人xyx性爽| 在线观看国产精品网站| 欧美一区二区日韩一区二区| 欧美r级电影在线观看| 亚洲自拍偷拍麻豆| 一区二区三区不卡视频| 五月天一区二区| 国产酒店精品激情| 日本乱人伦aⅴ精品| 国产精品资源网站| 午夜精品福利视频网站| 在线观看91视频| 亚洲二区在线观看| 国产成人av一区二区| 日韩视频一区二区三区在线播放| 亚洲国产成人av好男人在线观看| 成人黄色一级视频| 中文久久乱码一区二区| 成人在线视频一区二区| 国产精品日日摸夜夜摸av| 国产成人一区在线| 国产午夜亚洲精品羞羞网站| 九九九精品视频| 久久久久久久一区| 成人午夜免费av| 国产视频在线观看一区二区三区 | 捆绑紧缚一区二区三区视频 | 亚洲成人中文在线| 欧美久久一二区| 亚洲二区在线观看| 欧美高清视频不卡网| 亚洲成人高清在线| 日韩一级片在线观看| 精一区二区三区| 精品国产免费一区二区三区四区| 精品一区二区三区影院在线午夜 | xfplay精品久久| 性久久久久久久久久久久| 色先锋资源久久综合| 悠悠色在线精品| 欧美日韩高清不卡| 国产一区二区按摩在线观看| 国内精品国产三级国产a久久| 欧美夫妻性生活| 久久成人久久鬼色| 国产精品素人视频| 欧美亚洲一区二区在线| 蜜桃精品视频在线观看| 国产精品乱人伦一区二区| 欧美日韩综合不卡| 91久久久免费一区二区| 午夜欧美2019年伦理| 久久综合九色综合欧美98| 色综合视频在线观看| 青青草原综合久久大伊人精品 | www久久久久| 在线视频国内一区二区| 国产一区二区视频在线播放| 国产精品久久久久国产精品日日| 欧美性高清videossexo| 激情六月婷婷综合| 亚洲成人一区在线| 亚洲欧美综合另类在线卡通| 日韩精品在线一区| 在线观看网站黄不卡| 高清成人在线观看| 韩国成人在线视频| 青青草原综合久久大伊人精品优势| 中文字幕一区二区三区四区| 国产欧美一区二区精品性色| 亚洲欧美激情插| 狠狠色狠狠色合久久伊人| 色婷婷精品久久二区二区蜜臂av| 欧美日韩一区精品| 亚洲国产激情av| 日本中文字幕一区二区视频| 国产成人免费9x9x人网站视频| bt欧美亚洲午夜电影天堂| 久久99精品久久久久久国产越南| 九九国产精品视频| 精品亚洲成a人在线观看| 老司机精品视频导航| 色伊人久久综合中文字幕| 精品裸体舞一区二区三区| 国产精品视频在线看| 综合电影一区二区三区| 久久99精品久久久| 日本韩国一区二区三区| 国产精品香蕉一区二区三区| 久久美女艺术照精彩视频福利播放| 26uuu亚洲| 亚洲成人资源网| 777欧美精品| 日本大香伊一区二区三区| 欧美性猛片aaaaaaa做受| 国产精品福利一区| 国产揄拍国内精品对白| 自拍偷拍亚洲欧美日韩| 一区二区国产视频| 欧美一区二区三区四区五区| 国产欧美日韩亚州综合| 免费成人av在线| 欧美一区二区成人| 玖玖九九国产精品| 欧美成人三级电影在线| 日本一区中文字幕| 日韩女优毛片在线| 麻豆精品国产传媒mv男同| 日韩精品一区二区三区老鸭窝| 日韩国产欧美视频| 337p粉嫩大胆色噜噜噜噜亚洲 | 国产一区二区成人久久免费影院| 日韩精品视频网站| 久久综合久久99| 亚洲麻豆国产自偷在线| 午夜精品免费在线观看| 成人黄色网址在线观看| 色婷婷av久久久久久久| 日韩欧美国产一区在线观看| 国产精品国产三级国产专播品爱网| 欧美性一级生活| 99久久99久久精品免费看蜜桃| 午夜久久久影院| 亚洲mv在线观看| 懂色av中文字幕一区二区三区| 欧美日韩aaaaaa| 亚洲天堂av老司机| 国产一区二区三区在线观看精品| 在线精品国精品国产尤物884a | 在线精品观看国产| 日本一区二区三区在线不卡| 日韩和的一区二区| av动漫一区二区| 亚洲精品一区二区三区99| av电影在线观看一区| 欧美成人激情免费网| 亚洲国产裸拍裸体视频在线观看乱了| 国产一区二区美女| 日韩欧美高清一区| 天堂精品中文字幕在线| 91久久香蕉国产日韩欧美9色| 国产日产欧美一区二区三区| 激情欧美一区二区三区在线观看| 欧美日韩亚洲综合在线 | 一区二区三区中文字幕电影| 国产精品一区二区免费不卡| 日韩女同互慰一区二区| 香蕉久久夜色精品国产使用方法| 99久久久精品| 最好看的中文字幕久久| 懂色av一区二区三区免费观看| 欧美大片在线观看一区| 麻豆91小视频| 日韩午夜小视频| 丝袜美腿亚洲综合| 欧美一级国产精品| 婷婷国产在线综合| 欧美色视频在线| 亚洲综合成人在线视频| 欧美特级限制片免费在线观看| 亚洲人精品午夜| 在线亚洲精品福利网址导航| 亚洲欧美激情小说另类| 日本韩国一区二区三区视频| 亚洲已满18点击进入久久| 色av一区二区| 午夜电影一区二区| 欧美一区二区福利在线| 捆绑调教美女网站视频一区| 精品福利一二区| 国产高清在线观看免费不卡| 久久伊人蜜桃av一区二区| 国产又黄又大久久| 国产精品久久久久久亚洲伦 | 国产乱码精品一区二区三区忘忧草 | 美女一区二区三区在线观看| 欧美丰满一区二区免费视频| 日韩精品视频网| 久久理论电影网| 99热这里都是精品| 亚洲不卡av一区二区三区| 欧美一级精品在线| 国产mv日韩mv欧美| 亚洲免费观看在线视频| 91麻豆精品国产91久久久久久| 亚洲自拍偷拍九九九| 欧美性三三影院| 麻豆传媒一区二区三区| 国产欧美一二三区| 欧美亚洲另类激情小说| 久久se这里有精品| 亚洲欧美另类小说| 精品久久久影院| 成人av电影免费观看| 亚洲午夜国产一区99re久久|