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

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

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

?? java數(shù)據(jù)結(jié)構(gòu)與算法有很好的代碼
?? MHT
?? 第 1 頁 / 共 5 頁
字號:
        return next;
    }
    public Object getData(){
        return data;
    }
    public String toString(){
        return ""+data;
    }
}</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Go over the source, notice that =
it's nothing=20
more than just set and get functions (pretty simple). The two data =
members are=20
the <CODE>data</CODE> and <CODE>next</CODE>. The <CODE>data</CODE> =
member holds=20
the data of the node, and <CODE>next</CODE> holds the pointer to the =
next node.=20
Notice that <CODE>next</CODE> is of the same type as the class itself; =
it=20
effectively points to the object of same class!</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The <CODE>String toString()</CODE> =
method is=20
the Java's standard way to print things. If an object wants to be =
printed in a=20
special way, it will define this method, with instructions on how to =
print this=20
object. In our case, we just want to print the <CODE>data</CODE>. Adding =

<CODE>data</CODE> to a bunch of quotation marks automatically converts =
it to=20
type <CODE>String</CODE> (hopefully, our data will also have a=20
<CODE>toString()</CODE> method defined on it). Without this method, we =
get the=20
actual binary representation of the data members of this class (not a =
pretty nor=20
meaningful printout).</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Node based data structures provide =
for=20
dynamic growing and shrinking, and are the key to some complex =
algorithms (as=20
you'll see later). Now that we know how to implement a Node, lets get to =

something cool...</P>
<HR SIZE=3D1>

<H2><A name=3DLinked_Lists><I>Linked Lists...</I></A></H2>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; A linked list is just a chain of =
nodes, with=20
each subsequent node being a child of the previous one. Many programs =
rely on=20
linked lists for their storage because these don't have any evident=20
restrictions. For example, the array list we did earlier could not grow =
or=20
shrink, but node based ones can! This means there is no limit (other =
than the=20
amount of memory) on the number of elements they can store.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; A linked list has just one node, =
that node,=20
has links to subsequent nodes. So, the entire list can be referenced =
from that=20
one node. That first node is usually referred to as the head of the =
list. The=20
last node in the chain of nodes usually has some special feature to let =
us know=20
that it's last. That feature, most of the time is a <CODE>null</CODE> =
pointer to=20
the next =
node.</P><PRE><CODE>[node0]-&gt;[node1]-&gt;[node2]-&gt;[node3]-&gt;[node=
4]-&gt;null</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The example above illustrates the =
node=20
organization inside the list. In it, <CODE>node0</CODE> is the head =
node, and=20
<CODE>node4</CODE> is the last node, because it's pointer points to=20
<CODE>null</CODE>. Well, now that you know how it's done, and what is =
meant by a=20
linked list, lets write one. (I mean, that's why we're here, to actually =
write=20
stuff!)</P><PRE><CODE>import pOneChildNode;

public class pLinkedList{
    protected pOneChildNode head;
    protected int number;

    public pLinkedList(){
        head =3D null;
        number =3D 0;
    }
    public boolean isEmpty(){
        return head =3D=3D null;
    }
    public int size(){
        return number;
    }
    public void insert(Object obj){
        head =3D new pOneChildNode(obj,head);
        number++;
    }
    public Object remove(){
        if(isEmpty())
            return null;
        pOneChildNode tmp =3D head;
        head =3D tmp.getNext();
        number--;
        return tmp.getData();
    }
    public void insertEnd(Object obj){
        if(isEmpty())
            insert(obj);
        else{
            pOneChildNode t =3D head;
            while(t.getNext() !=3D null)
                t=3Dt.getNext();
            pOneChildNode tmp =3D
                new pOneChildNode(obj,t.getNext());
            t.setNext(tmp);
            number++;
        }
    }
    public Object removeEnd(){
        if(isEmpty())
            return null;
        if(head.getNext() =3D=3D null)
            return remove();
        pOneChildNode t =3D head;
        while(t.getNext().getNext() !=3D null)
            t =3D t.getNext();
        Object obj =3D t.getNext().getData();
        t.setNext(t.getNext().getNext());
        number--;
        return obj;
    }
    public Object peek(int n){
        pOneChildNode t =3D head;
        for(int i =3D 0;i&lt;n &amp;&amp; t !=3D null;i++)
            t =3D t.getNext();
        return t.getData();
    }
}</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Before we move on, lets go over =
the source.=20
There are two data members, one named <CODE>head</CODE>, and the other =
named=20
<CODE>number</CODE>. Head is the first node of the list, and =
<CODE>number</CODE>=20
is the total number of nodes in the list. Number is primarily used for =
the=20
<CODE>size()</CODE> method. The constructor, <CODE>pLinkedList()</CODE> =
is self=20
explanatory. The <CODE>size()</CODE> and <CODE>isEmpty()</CODE> methods =
are also=20
pretty easy.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Here comes the hard part, the =
insertion and=20
removal methods. Method <CODE>insert(Object)</CODE> creates a new=20
<CODE>pOneChildNode</CODE> object with <CODE>next</CODE> pointer =
pointing to the=20
current <CODE>head</CODE>, and <CODE>data</CODE> the data which is =
inserted. It=20
then sets the <CODE>head</CODE> to that new node. If you think about it, =
you'll=20
notice that the <CODE>head</CODE> is still saved, and the new node =
points to=20
it.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Method <CODE>Object =
remove()</CODE> works in=20
a very similar fashion, but instead of inserting, it is removing. It =
first=20
checks to see if the list is <CODE>isEmpty()</CODE> or not, if it is, it =
returns=20
a <CODE>null</CODE>. It then saves the current <CODE>head</CODE> node, =
and then=20
changes it to accommodate the removal (think about the logic), =
decrements the=20
<CODE>number</CODE>, and returns the <CODE>data</CODE> from the =
previously saved=20
node.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; In the method=20
<CODE>insertEnd(Object)</CODE>, we're actually inserting at the end of =
the list.=20
We first check to see if the list is <CODE>isEmpty()</CODE>, if it is, =
we do a=20
regular insertion (since it really doesn't matter which direction we're =
coming=20
from if the list is <CODE>empty</CODE>). We then setup a loop to search =
for the=20
end. The end is symbolized by the <CODE>next</CODE> pointer of the node =
being=20
<CODE>null</CODE>. When we get to the end, we create a new node, and =
place it at=20
the end location. Incrementing <CODE>number</CODE> before we return.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Method <CODE>Object =
removeEnd()</CODE> works=20
in a similar fashion as <CODE>insertend(Object)</CODE> method. It also =
goes=20
through the whole list to look for the end. At the beginning, we check =
if the=20
list is not <CODE>isEmpty()</CODE>, if it is, we return a =
<CODE>null</CODE>. We=20
then check to see if there is only one element in the list, if there is =
only=20
one, we remove it using regular <CODE>remove()</CODE>. We then setup a =
loop to=20
look for the node who's child is the last node. It is important to =
realize that=20
if we get to the last node, we won't be able to erase it; we need the =
last=20
node's parent node. When we find it, we get the <CODE>data</CODE>, setup =

necessary links, decrement <CODE>number</CODE>, and return the=20
<CODE>data</CODE>.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The <CODE>Object peek(int)</CODE> =
method=20
simply goes through the list until it either reaches the element =
requested, or=20
the end of the list. If it reaches the end, it should return a=20
<CODE>null</CODE>, if not, it should return the correct location inside =
the=20
list.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; As I have said before, it is very =
important=20
to actually test. The ideas could be fine, and logical, but if it =
doesn't work,=20
it doesn't work. So, lets convert our <CODE>pArrayListTest</CODE> driver =
to=20
accommodate this class.</P><PRE><CODE>import java.io.*;
import pLinkedList;

class pLinkedListTest{
    public static void main(String[] args){
        pLinkedList l =3D new pLinkedList();
        Integer j =3D null;
        int i;
        System.out.println("starting...");
        for(i=3D0;i&lt;5;i++){
            j =3D new Integer((int)(Math.random() * 100));
            l.insert(j);
            System.out.println("insert: " + j);
        }
        for(;i&lt;10;i++){
            j =3D new Integer((int)(Math.random() * 100));
            l.insertEnd(j);
            System.out.println("insertEnd: " + j);
        }
        for(i=3D0;i&lt;l.size();i++)
            System.out.println("peek "+i+": "+l.peek(i));
        for(i=3D0;i&lt;5;i++)
            System.out.println("remove: " + ((Integer)l.remove()));
        while(!l.isEmpty())
            System.out.println("removeEnd: " + =
((Integer)l.removeEnd()));
        System.out.println("Done ;-)");
    }
}</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; The test driver is nothing =
special, it's=20
just a pretty simple conversion of the old test driver, so, I wont spend =
any=20
time discussing it. The output follows.</P><PRE><CODE>starting...
insert: 65
insert: 78
insert: 21
insert: 73
insert: 62
insertEnd: 82
insertEnd: 63
insertEnd: 6
insertEnd: 95
insertEnd: 57
peek 0: 62
peek 1: 73
peek 2: 21
peek 3: 78
peek 4: 65
peek 5: 82
peek 6: 63
peek 7: 6
peek 8: 95
peek 9: 57
remove: 62
remove: 73
remove: 21
remove: 78
remove: 65
removeEnd: 57
removeEnd: 95
removeEnd: 6
removeEnd: 63
removeEnd: 82
Done ;-)</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Look over the output, make sure =
you=20
understand why you get what you get. Linked lists are one of the most =
important=20
data structures you'll ever learn, and it really pays to know them well. =
Don't=20
forget that you can always experiment. One exercise I'd like to leave up =
to the=20
reader is to create a circular list. In a circular list, the last node =
is not=20
pointing to <CODE>null</CODE>, but to the first node (creating a =
circle).=20
Sometimes, lists are also implemented using two pointers; and there are =
many=20
other variations you should consider and try yourself. You can even make =
it=20
faster by having a "dummy" first node and/or "tail" node. This will =
eliminate=20
most special cases, making it faster on insertions and deletions.</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; I guess that's it for the lists, =
next, I'll=20
show you how to do simple and easy tricks to re-use code.</P>
<HR SIZE=3D1>

<H2><A name=3DReusing_Tricks><I>Reusing Tricks...</I></A></H2>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; We have already written quite a =
lot of=20
useful stuff, and there might come a time, when you're just too lazy to =
write=20
something new, and would like to reuse the old source. This section will =
show=20
you how you can convert some data structures previously devised, to =
implement a=20
stack and a queue, with almost no creativity (by simply reusing the old=20
source).</P>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; Before we start, lets review the =
function of=20
a stack. It has to be able to push and pop items of from one end. What =
structure=20
do we know that can do something similar? A list! Lets write a list=20
implementation of a stack.</P><PRE><CODE>import pLinkedList;

public class pEasyStack{
    protected pLinkedList l;

    public pEasyStack(){
        l =3D new pLinkedList();
    }
    public boolean isEmpty(){
        return l.isEmpty();
    }
    public void push(Object o){
        l.insert(o);
    }
    public Object pop(){
        return l.remove();
    }
}</CODE></PRE>
<P align=3Djustify>&nbsp;&nbsp;&nbsp; See how easily the above code =
simulates a=20
stack by using a list? It may not be the best implementation, and it's =
certainly=20
not the fastest, but when you need to get the project compiled and =
tested, you=20
don't want to spend several unnecessary minutes writing a full blown =
optimized=20
stack. Test for the stack follows:</P><PRE><C

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产三级精品三级| 韩国成人福利片在线播放| 国产精品99久久久久久有的能看 | 久久―日本道色综合久久| 另类小说图片综合网| 精品欧美一区二区在线观看| 国产精品正在播放| 中文字幕永久在线不卡| 色婷婷国产精品综合在线观看| 亚洲影视资源网| 日韩一区二区电影在线| 国产不卡在线一区| 亚洲日本韩国一区| 日韩一区二区免费在线电影 | 欧美国产97人人爽人人喊| 99久久综合色| 亚洲成人资源网| 国产亚洲欧洲一区高清在线观看| 波多野洁衣一区| 性做久久久久久| 国产视频一区在线观看| 91国内精品野花午夜精品| 日韩精品免费视频人成| 欧美极品少妇xxxxⅹ高跟鞋| 日本久久一区二区| 国产一区二区三区最好精华液| 亚洲天堂中文字幕| 精品久久人人做人人爽| 99这里只有精品| 久久99精品久久久久久动态图| 亚洲欧美在线观看| 日韩免费视频线观看| 99热这里都是精品| 精品综合久久久久久8888| 亚洲美女免费在线| 国产婷婷色一区二区三区在线| 欧美体内she精高潮| 盗摄精品av一区二区三区| 日韩二区在线观看| 亚洲男人天堂一区| 免费成人在线影院| 亚洲摸摸操操av| 国产三级精品在线| 精品久久久久av影院| 欧美在线你懂得| 99re在线精品| 国产mv日韩mv欧美| 卡一卡二国产精品| 午夜精品福利在线| 亚洲精品日日夜夜| 国产精品萝li| 精品国产不卡一区二区三区| 51久久夜色精品国产麻豆| 日本高清无吗v一区| 成人黄色在线看| 国精产品一区一区三区mba视频 | 成人午夜视频在线| 激情六月婷婷综合| 免费观看久久久4p| 亚洲第一激情av| 樱桃国产成人精品视频| 国产精品视频线看| 欧美国产欧美亚州国产日韩mv天天看完整 | 一区二区三区国产精华| 国产精品嫩草久久久久| 国产日韩成人精品| 久久精品人人爽人人爽| 日韩欧美电影一二三| 日韩欧美视频一区| 91精品国产美女浴室洗澡无遮挡| 欧美日本一区二区在线观看| 欧美日韩国产综合一区二区三区 | 国产成人精品综合在线观看| 国产永久精品大片wwwapp| 青青草国产精品97视觉盛宴| 日韩专区在线视频| 美女网站视频久久| 麻豆免费看一区二区三区| 日韩不卡一区二区| 久久91精品久久久久久秒播| 久久不见久久见中文字幕免费| 久久精品国产亚洲5555| 国产精品自在在线| 不卡影院免费观看| 色综合久久精品| 在线日韩一区二区| 777奇米四色成人影色区| 正在播放亚洲一区| 久久综合九色综合97婷婷女人 | 国产精品1区2区3区在线观看| 国产乱码精品一区二区三区忘忧草| 国产成人免费视频网站高清观看视频| 韩国精品在线观看| av色综合久久天堂av综合| 在线亚洲人成电影网站色www| 欧美群妇大交群的观看方式| 欧美一卡二卡在线| 国产网站一区二区| 亚洲在线视频一区| 免费久久99精品国产| 高清在线成人网| 在线观看国产一区二区| 日韩视频中午一区| 国产精品久线在线观看| 亚洲成人激情av| 韩国精品免费视频| 欧洲精品在线观看| 精品久久久久久久久久久久久久久久久| 国产亚洲欧美一级| 亚洲成人激情av| 国产宾馆实践打屁股91| 欧美视频日韩视频在线观看| 欧美成人bangbros| 亚洲欧美色一区| 麻豆精品国产91久久久久久| 成人av在线播放网站| 7777精品伊人久久久大香线蕉的| 国产亚洲一二三区| 日韩影院精彩在线| av综合在线播放| 欧美成人a∨高清免费观看| 中文字幕综合网| 美女一区二区三区| 欧洲一区在线观看| 国产清纯美女被跳蛋高潮一区二区久久w| 亚洲精品乱码久久久久久久久| 欧美系列一区二区| 国产精品福利影院| 蜜臀久久99精品久久久画质超高清 | 精品国产麻豆免费人成网站| √…a在线天堂一区| 七七婷婷婷婷精品国产| a4yy欧美一区二区三区| 欧美成人精品1314www| 亚洲无人区一区| 懂色中文一区二区在线播放| 91麻豆精品国产91久久久久久| 136国产福利精品导航| 国产一区二区在线影院| 欧美一区二区三区视频免费| 亚洲视频狠狠干| 国产99久久久久久免费看农村| 91精品国产乱| 亚洲午夜久久久久久久久久久| 国产精品1区2区3区在线观看| 欧美一区二区性放荡片| 亚洲在线视频一区| 色哟哟一区二区在线观看| 国产欧美日韩视频一区二区 | 国产精品456| 欧美大片免费久久精品三p| 亚洲第一精品在线| 色94色欧美sute亚洲线路一久| 欧美激情在线一区二区三区| 国产在线不卡一区| 精品欧美一区二区三区精品久久| 偷偷要91色婷婷| 欧美日韩成人高清| 天堂va蜜桃一区二区三区| 欧美三级一区二区| 亚洲国产精品影院| 欧美精品粉嫩高潮一区二区| 亚洲午夜精品在线| 欧美撒尿777hd撒尿| 亚洲福利一区二区三区| 欧美日韩精品福利| 亚洲图片自拍偷拍| 91精品国产入口在线| 伦理电影国产精品| 精品88久久久久88久久久| 国产一区91精品张津瑜| 久久嫩草精品久久久久| 国产美女精品在线| 国产精品情趣视频| 91色九色蝌蚪| 亚洲成av人片在线观看无码| 91精品国产麻豆| 国内精品伊人久久久久av一坑| 久久伊99综合婷婷久久伊| 国产白丝网站精品污在线入口| 一区视频在线播放| 欧美日韩精品专区| 精品一区二区三区在线播放| 久久疯狂做爰流白浆xx| 久久精品一区二区三区四区| 成人精品视频.| 一区二区成人在线| 欧美一区二区啪啪| 国产精品一区专区| 一区二区三区四区在线播放 | 日韩欧美在线网站| 国产精品夜夜嗨| 亚洲人成伊人成综合网小说| 欧美日韩国产一级二级| 国产麻豆欧美日韩一区| 成人欧美一区二区三区1314| 在线成人免费视频| 国产宾馆实践打屁股91| 亚洲国产裸拍裸体视频在线观看乱了| 日韩午夜小视频|