From bb4adfd1ab2e7b5aab3d241824e5f96c975bfc5c Mon Sep 17 00:00:00 2001 From: cookiel <1395692506@qq.com> Date: Wed, 4 Nov 2020 08:05:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=8C=E9=93=BE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- work/Test01/LinkedList.class | Bin 0 -> 1264 bytes work/Test01/LinkedList.java | 55 +++++++++++++++++++++++++++++++++++ work/Test01/Main.class | Bin 0 -> 562 bytes work/Test01/Main.java | 15 ++++++++++ work/Test01/Node.class | Bin 0 -> 424 bytes work/Test01/Node.java | 7 +++++ work/Test02/LinkedList.class | Bin 0 -> 1304 bytes work/Test02/LinkedList.java | 48 ++++++++++++++++++++++++++++++ work/Test02/Main.class | Bin 0 -> 562 bytes work/Test02/Main.java | 15 ++++++++++ work/Test02/Node.class | Bin 0 -> 465 bytes work/Test02/Node.java | 8 +++++ 12 files changed, 148 insertions(+) create mode 100644 work/Test01/LinkedList.class create mode 100644 work/Test01/LinkedList.java create mode 100644 work/Test01/Main.class create mode 100644 work/Test01/Main.java create mode 100644 work/Test01/Node.class create mode 100644 work/Test01/Node.java create mode 100644 work/Test02/LinkedList.class create mode 100644 work/Test02/LinkedList.java create mode 100644 work/Test02/Main.class create mode 100644 work/Test02/Main.java create mode 100644 work/Test02/Node.class create mode 100644 work/Test02/Node.java diff --git a/work/Test01/LinkedList.class b/work/Test01/LinkedList.class new file mode 100644 index 0000000000000000000000000000000000000000..3f2ccb48da8e7bb88cfab8e5821d9c060ba468bf GIT binary patch literal 1264 zcmbVMT~8B16g|_g?Usc?X+@~Yf+EX8DW85&tO~+YL1T#tj|<)4LfJNDOY|4%Y7zso$rqY-y z#xbEFmq1*`L@+6L`8cNJIxWpi0<)NtW?sQP1@{FauWhR$5G$?MDt3Wq&vL3fFFLN{ z6$Qe^*eiOMc`J}CIj+6l+~2Yr8`f5po`hAYY}8g8HP;i!7^Pk7(8^aWcPIaRYuDcP z3NpL1>{;7;YgXM)B547&?CiLf*K80YW^AnZajFmY(zY4`(R#y?n8xDD!e!LrWf!@W zYt6>Cz3NC}lIosaDLDt;q$H)`8u~Q!BCR2VG+UAlOK(=g1Edu^)UW_5(AVyv?2*LI zQq!qc?1qL#Jkn6aVi!Wbb09htVfJ21+h}knlHpfp9T{Djn`ix$4 zLW0Qy@s5y@yY;}yUG4-iStR5a873&u!2+G=W{C`v(AmKV%bVmsL(dIHs0e+7uHa@5 zZu!ZB { + private Node head; + private Node tail; + + public LinkedList() { + head = null; + tail = null; + } + + public void addToFront(E item) { + Node node = new Node(item); + + if (this.head == null) { + this.head = node; + this.tail = this.head; + } else{ + Node temp = head; + this.head = node; + this.head.next = temp; + } + } + + + public void addToRear(E item) { + Node newNode = new Node(item); + if (this.head == null) { + this.head = newNode; + this.tail = this.head; + } else { + + Node temp = this.tail; + tail = newNode; + temp.next = tail; + /* + Node temp = this.head; + while(temp.next != null){ + temp = temp.next; + } + temp.next = newNode; + tail = temp.next; + */ + + } + } + + public void print() { + Node temp = this.head; + while(temp.next != null){ + System.out.print(temp.item + " -> "); + temp = temp.next; + } + System.out.println(temp.item); + } +} + diff --git a/work/Test01/Main.class b/work/Test01/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..acd5ba79cd19013b43688c117c0f04ebc61dbca7 GIT binary patch literal 562 zcmYk2+e*Vg5QhJ4ldg?X>#5d5JzcdH6vQhPZwf*oDtLnGRobj2S`&$>kK;Rd(~5!* z;6sW3rjZ)R%+KsUv)}CZ&&L;lJ#1RYV@6`uLIyJy<}j~SQHKQ`N)n3_O9Ht=Kk(xt zfo!FEEnw6`PYFypexOc!k1Z8lx~(oN#-r;80>#R$bML;mJ6$*E>|Df=A9N0MqjeGX zqP9BrwK;!6^S1WcurSV3&U;Xv<3Gm|%QjX}wy}ye8|yl3XpfPi zrA82|j*0~2i`(s~vpbE{sQzP09S6MB^}NgQI0^&Kn6Lcv3 literal 0 HcmV?d00001 diff --git a/work/Test01/Main.java b/work/Test01/Main.java new file mode 100644 index 0000000..2211883 --- /dev/null +++ b/work/Test01/Main.java @@ -0,0 +1,15 @@ +class Main { + public static void main(String[] args) { + LinkedList ll = new LinkedList(); + ll.addToFront(1); + ll.addToFront(2); + ll.addToFront(5); + ll.addToFront(6); + ll.addToFront(7); + ll.addToRear(3); + ll.addToRear(8); + ll.addToRear(9); + ll.addToRear(10); + ll.print(); + } +} \ No newline at end of file diff --git a/work/Test01/Node.class b/work/Test01/Node.class new file mode 100644 index 0000000000000000000000000000000000000000..a383363383e004072772b0293411ecf05b408603 GIT binary patch literal 424 zcmZWlyH3ME5S+6e8#^WjLwHtnj*&AhoM?CI;LO3ffTe1=6bQ3<{+jm}c{%Gp7jrqS z9|YWynw5FIuB3oD95g*byZ(B1#7LO>WvO33#K`x|+%-r3GC5p&Pw}k9}PD@X+>Q!{Jcf5;*w3 zAa{y-6I}5cEuP4r5f6dAZRXNb { + E item; + Node next = null; + Node(E item) { + this.item = item; + } +} \ No newline at end of file diff --git a/work/Test02/LinkedList.class b/work/Test02/LinkedList.class new file mode 100644 index 0000000000000000000000000000000000000000..202467e741c2844d4a03aa3bbf3435e2a306ed93 GIT binary patch literal 1304 zcmbV~T~E_s6vzKvw{;zb!N%lm!vO+Y#~1>>F+>GHO$HiAOt>tp!NTa4(Gk7%%W$oM zkx1gDCVm1xj8Xqj8y#?fmo2 z9dpYmi0Jl`V{GlN8Z|eFvr@F~rnnqnhpjNj;&h-59+~uqb zmsMmbRU7p!bHx&10(I9c7p;9~Qb1|wL9d2x#5G()oGpolg*KsKPG}2=E11`CA8fm) z)kw)9$@XHys+7&Th6i}4;Sm;@A(dN5iSv?%$5>XdqG1?MG(1IuG%WxLovn1a4KY%$QLCDNA?86A)7TShvRtR=RdWa$wVG*jsky86aVFwi zXH0s|-!m36|L_kvRnJR8clxp;GsfJ$&(mLcC%^0Poha_kD>jDs!ee~)K7QPod*agg z_k+7ZFJ&KZGqg+mNAwd&x^xVm5b}GfB=l2882|(*gM9u9IuN2|00{<)1n(fb9)(l* zH?k)Ptm;SbeL+m05Xr=a`3{j3r!`N>Q|=hSoM%)-F`rv(j3t0J%64?JR2&hc(1lTA z=a?89|8L5f^M|HUP{TrzQFaw&pKCf`M_0oF{AD@m?Fat)Dd zm|P>|xUvu(e@@fnus*fDO`$& sKflq(Gj_GO`neP!!}aLUkVP63n8GAk@-3DCXQZ>HH>DAxigAzr0-3P_F8}}l literal 0 HcmV?d00001 diff --git a/work/Test02/LinkedList.java b/work/Test02/LinkedList.java new file mode 100644 index 0000000..fcf4b21 --- /dev/null +++ b/work/Test02/LinkedList.java @@ -0,0 +1,48 @@ +public class LinkedList { + private Node head; + private Node tail; + + public LinkedList() { + head = null; + tail = null; + } + + public void addToFront(E item) { + Node node = new Node(item); + + if (this.head == null) { + this.head = node; + this.tail = this.head; + } else{ + Node temp = head; + this.head = node; + this.head.next = temp; + temp.pre = this.head; + //temp = null; + } + } + + public void addToRear(E item) { + Node newNode = new Node(item); + if (this.head == null) { + this.head = newNode; + this.tail = this.head; + } else { + + Node temp = this.tail; + tail = newNode; + tail.pre = temp; + temp.next = tail; + } + } + + public void print() { + Node temp = this.head; + while(temp.next != null){ + System.out.print(temp.item + " -> "); + temp = temp.next; + } + System.out.println(temp.item); + } +} + diff --git a/work/Test02/Main.class b/work/Test02/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..acd5ba79cd19013b43688c117c0f04ebc61dbca7 GIT binary patch literal 562 zcmYk2+e*Vg5QhJ4ldg?X>#5d5JzcdH6vQhPZwf*oDtLnGRobj2S`&$>kK;Rd(~5!* z;6sW3rjZ)R%+KsUv)}CZ&&L;lJ#1RYV@6`uLIyJy<}j~SQHKQ`N)n3_O9Ht=Kk(xt zfo!FEEnw6`PYFypexOc!k1Z8lx~(oN#-r;80>#R$bML;mJ6$*E>|Df=A9N0MqjeGX zqP9BrwK;!6^S1WcurSV3&U;Xv<3Gm|%QjX}wy}ye8|yl3XpfPi zrA82|j*0~2i`(s~vpbE{sQzP09S6MB^}NgQI0^&Kn6Lcv3 literal 0 HcmV?d00001 diff --git a/work/Test02/Main.java b/work/Test02/Main.java new file mode 100644 index 0000000..2211883 --- /dev/null +++ b/work/Test02/Main.java @@ -0,0 +1,15 @@ +class Main { + public static void main(String[] args) { + LinkedList ll = new LinkedList(); + ll.addToFront(1); + ll.addToFront(2); + ll.addToFront(5); + ll.addToFront(6); + ll.addToFront(7); + ll.addToRear(3); + ll.addToRear(8); + ll.addToRear(9); + ll.addToRear(10); + ll.print(); + } +} \ No newline at end of file diff --git a/work/Test02/Node.class b/work/Test02/Node.class new file mode 100644 index 0000000000000000000000000000000000000000..d5d0e569664ec23fdd06c248a33be2f4e3f1a48a GIT binary patch literal 465 zcmZWlO-sW-6r4?BV$#@D`{B3XEsbC=o;2hl^%Ux%rT3&RC8bSENX5V9p$H!Q0sbg) z)`EyR?Cg7Q=gqu*pI`4E0B&&Mz{H`A9ULh*R&ZkB)WVs7k(F{Ga1hUu=cG4J@@ele zoykdgCtwe=X`YnpLJH`kJ}X8pUrGTp9xR_E^V&}k@-1SfuN2b^vpg#!fwo^2?T#sO z&t?HH&T=_eFH%{Il60;*eF`atANFsny-~F!;0%}RVj>?hC19(uuGLRmcsO@agX^NM zz``z_)w@9B|6e(}-yP$Ui!r$}orio-kdX$5NTuI=k2yvE6tJ p5F2O;^x$d( { + E item; + Node next = null; + Node pre = null; + Node(E item) { + this.item = item; + } +} \ No newline at end of file -- Gitee