From 77d8a327ef5dace88582684697552d65e1e757e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=92=A7=E5=9E=AB=E6=AA=BD=E9=90=9E=E7=A0=95?= <407837686@qq.com> Date: Tue, 17 Nov 2020 22:25:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/work1/MainTest.class | Bin 0 -> 1022 bytes base/work1/MainTest.java | 22 ++++++++++ base/work1/MyStack.class | Bin 0 -> 1661 bytes base/work1/MyStack.java | 55 ++++++++++++++++++++++++ base/work2/LLStack.class | Bin 0 -> 1760 bytes base/work2/LLStack.java | 86 +++++++++++++++++++++++++++++++++++++ base/work2/MainTest.class | Bin 0 -> 469 bytes base/work2/MainTest.java | 24 +++++++++++ base/work2/StackNode.class | Bin 0 -> 337 bytes base/work3/Main.class | Bin 0 -> 435 bytes base/work3/Main.java | 14 ++++++ base/work3/MyQueue.class | Bin 0 -> 1497 bytes base/work3/MyQueue.java | 55 ++++++++++++++++++++++++ base/work4/LLQueue.class | Bin 0 -> 1615 bytes base/work4/LLQueue.java | 82 +++++++++++++++++++++++++++++++++++ base/work4/Main.class | Bin 0 -> 444 bytes base/work4/Main.java | 17 ++++++++ base/work4/MyNode.class | Bin 0 -> 312 bytes 18 files changed, 355 insertions(+) create mode 100644 base/work1/MainTest.class create mode 100644 base/work1/MainTest.java create mode 100644 base/work1/MyStack.class create mode 100644 base/work1/MyStack.java create mode 100644 base/work2/LLStack.class create mode 100644 base/work2/LLStack.java create mode 100644 base/work2/MainTest.class create mode 100644 base/work2/MainTest.java create mode 100644 base/work2/StackNode.class create mode 100644 base/work3/Main.class create mode 100644 base/work3/Main.java create mode 100644 base/work3/MyQueue.class create mode 100644 base/work3/MyQueue.java create mode 100644 base/work4/LLQueue.class create mode 100644 base/work4/LLQueue.java create mode 100644 base/work4/Main.class create mode 100644 base/work4/Main.java create mode 100644 base/work4/MyNode.class diff --git a/base/work1/MainTest.class b/base/work1/MainTest.class new file mode 100644 index 0000000000000000000000000000000000000000..487c6909a6cdbc5ca1854d713b9d6b96124b22fc GIT binary patch literal 1022 zcmaJ<+fEZv6kVsZo#}82Z7CEl;9XiOR1vEJqJp9|MNCRah>6J*4(&iYZQ3ab&&I?* zF!2c!Up3K~fl%WI_#Il~lYd~`r=*5}W4U=Ig{5-j>@9MFfZf0UBt7Mp&S(&J% z3YF4^STba=cbS4$McJB^u^dAPF(}J>DNEnjk>(8ragLj~#c>-mR6VO_b$N*_rTf|) zR?^#I!{V4lh+_^R1$Q{+ahD;~4r;(ys2I6TQDPXbeRyAcW7qay|9)rxeD(6zm;E1y zM}NM)<+z9Y91B>K+5?VM6oWO(=axj0pPr|fBMs`qk^;|`)Y)L*6 zkq$zd5wnzCtdz41gW(QuW0(eAMPkmX^Fh=X3&pOfQ+s7gN$a0<^zGuOj!lRihG4i8dK28SYAwkBsisJ)b4 zClc!v!-z>7{Wv#^`+teTc({8Te_F1GJ6*`3+#wB2rLYr9ass%#fw%UaP&i={}h*iv-Sgc1|C-3d-Wc&YJ5&0BB$M;b`<`>2bDrnCGr#}4 z`~W~d-VQ-WGKfyRAg15Ii?SXL(YzGI%NQ{6N(e_VD1k!;j)u^Hq?lJt49hwsvByk| z$mY0-*G!x+F)F*0CSEr&X5f@UAe}0wXFgD9JwHC1zL-vA)A~{prhG)f$fZ9_ zIUm^yYD~dbE)&fI7vnPWZN#C$#RpvYihC*l^mvBSc4>`(}A6~{ssq86S* zkAXKVjAMcltSo%Ca_`!o%b)&r|6@J|PFtA784CxIQ0Q34a9bFuIN6L{vhXI}QV6d8 z@MG<(FKVA$x3CvI3K4<(=GMcT%MZW1~xMAw$@2)J|8AOq=Q(avWS4s4wITEK?kZjy=xH^qAwb>n5& z8o!;l^r>*z&96k~H|K*U1Ld101Fx@~K35Zpmthy}Zth0t*SL1Y??A=1C1~;J5`6La zukif_eF^?WdKLE2w!=?r5Z{j=ahhm55u%sl_3#c6O);v80GhS{L%#vt_Y+UFI!2)G zZN#%Y@k6tQ`6bGwqm_0JvvEmpm2~Mr&pZvIWeuaHjc>ee~0_*Qhk?8&^KNvdiq2b&eShB66G15d+MYALj#O=BZ0lv49dpnxZfiQXZ zP~TxHEKJyRnALj`_j;IRsPGtI4`Hu|7J*!^_qdxWJ;QF2RYW4K|5Mvly_-MS6JUFz10k$Lhqoi3*)b`9(!Zj89`HN0l#A9&2;vZv+A z4Lr7aT55yQ@6oqTDALC6qgAv=I`|?Lqe9Bn@{)RVV0IDq^A8; tG>K7O15q^uU-%#B>Tmj${Bk^!QLaML7kNhLxR=wtSOeVk@l3;^{{VyyU#kEB literal 0 HcmV?d00001 diff --git a/base/work1/MyStack.java b/base/work1/MyStack.java new file mode 100644 index 0000000..5fccb2b --- /dev/null +++ b/base/work1/MyStack.java @@ -0,0 +1,55 @@ +public class MyStack +{ + private Object[] aStack; + private int maxSize; + private int top = -1; + + public MyStack(int size){ //设置栈数组的长度 + maxSize = size; + aStack = new Object[maxSize]; + } + + public boolean isEmpty(){ + return top == -1; + } + + public boolean isFull(){ + return top == maxSize-1; + } + + public void push(Object value){ + if(isFull()){ + System.out.println("栈满了!!"); + return; + } + aStack[++top] = value; + System.out.println(value+"被压入"); + } + + public void pop(){ + if(isEmpty()){ + System.out.println("栈是空的!!"); + return; + } + System.out.println(aStack[top--]+"被弹出"); + } + + public Object peek(){ + + if(isEmpty()){ + System.out.println("栈是空的!!"); + } + return aStack[top]; + } + + public void printStack(){ + if(isEmpty()){ + System.out.println("空栈无法打印输出!!"); + return; + } + for(int i=top ;i>=0 ;i-- ){ + //System.out.printf("aStack[%d]=%d、",i,aStack[i]); + System.out.println("aStack["+i+"]="+aStack[i]); + } + } +} \ No newline at end of file diff --git a/base/work2/LLStack.class b/base/work2/LLStack.class new file mode 100644 index 0000000000000000000000000000000000000000..7364d2742be2649659f494d1dfe81ac8dcb81896 GIT binary patch literal 1760 zcmaJ?>rdNN7=BJ$`fJONQA^oii~;Hd3LD7SMGK6}VBiX47Ez`jEbz@CnP%*15I z8-CbgvMjr(2{SQ^m&Bn^CXjvfgMWshFh4Evvr(V-*HRj{nY8DezURF>&-=Uwe*1g% z0f2VAd1>L<{%9h3iT;Vy>^tN}&xByn6EophGLS{2;0nf5GgHPuSaRz* z^Pvl&iy&D0aRjm?XgSy{T|y+L%!&-~94& z=JTr?_b+eU|1R_Khg(YvkJfMN7{}{6-VjLRm|($&Uw@xj|0VP3s*ZDblZL#n!hRN$ zsy7xkf4;u?*|p4-dk-I6qwjY4@{P5tbok>=Ix~Ndhs^4Avq%v23YOZ76e`~__YTxE zlNXFBDp_C(UYboBQ8qiC;zfDDbPmT`My2bdW`v>~fwCu9;&4?ILLxyi3$LN0?9m#lB2L*4#3lGP>Vb$yuj7PFu)F5&b>b8-a)(Ec*WhPmSOQ( zmtpl)EyK1Gy&FaJaWYz7VKJYhjxv-m2gfv*shxSG@H4(8#xKFP0L^w6HtP>GT1*gj z)4>fNEk&@Db_-MvELVZv%3U&)NQSST67AiNF76iZW^6P0f-RCJ4f@h3x&{3w*gaYr zj>R=NC#qK98s5G+sGEEVCO1PioI}Cl1hqF zOF<4$k`|s?`D%|-hE57`idLcMgvI?AYBU@q&_j8J{v=Fk`OPdI6KIJ57253DF(O~X zu89?tdfaKVpOz(f(kSzI`7@1jI%lOaNlXg~A-RIxfr8jQPmLwtfKOO2L1!xxc}7NE2*q zf}i|b^8CLcd*Oe!fPaPX7sV=h*ybV#15L#EE2??N6PvJCysGFW7lFI~{JwJ|^IE8w xpTIi^ypzCB5O_Cr>Y+Bhq|ry1C((s|3{bC844PnFuu?HE6{{uWRx{s={{okzdtU$m literal 0 HcmV?d00001 diff --git a/base/work2/LLStack.java b/base/work2/LLStack.java new file mode 100644 index 0000000..3533004 --- /dev/null +++ b/base/work2/LLStack.java @@ -0,0 +1,86 @@ +public class LLStack{ + StackNode top; + private int count; + private int maxSize; + + public LLStack(){ + } + + public LLStack(int size){ //设置栈能容纳的大小 + top = null; + count = 0; + maxSize = size; + } + + public boolean isFull(){ + return count == maxSize; + } + + public boolean isEmpty(){ + return count <=0 ; + } + + public void push(int value){ + if(isFull()){ + System.out.println("栈满了!!"); + return; + } + StackNode node = new StackNode(value); + if(isEmpty()){ + top = node; + count++; + return; + } + node.next = top; + top = node; + count++; + } + + public void pop(){ + if(isEmpty()){ + System.out.println("栈是空的!!"); + return; + } + if(count==1){ + System.out.println("最后一个元素:"+top.element+"被弹出"); + top = null; + count--; + return; + } + StackNode temp = new StackNode(); + System.out.println("元素:"+top.element+"被弹出"); + temp = top; + top = top.next; + temp.next = null; + count--; + } + + public void printLLStack(){ + if(isEmpty()){ + System.out.println("空栈无法打印输出!!"); + return; + } + System.out.println("从栈顶到栈底:"); + StackNode temp = new StackNode(); + temp = top; + while(temp.next != null){ + System.out.println(temp.element); + System.out.println(" v"); + temp = temp.next; + } + System.out.println(temp.element); + } + + +} +class StackNode{ + int element; + StackNode next; + + public StackNode(int n){ + element = n; + next = null; + } + public StackNode(){ + } +} diff --git a/base/work2/MainTest.class b/base/work2/MainTest.class new file mode 100644 index 0000000000000000000000000000000000000000..9bdd46c24fb56a415e5495e2076bb6f7dd6d59ad GIT binary patch literal 469 zcmZvZ%SyvQ7=_QIm$YMQ)4P{e&{eczMO=s$5xjs9b zfDa{}35pvB=9`&+&YyF_e15%s0N6)OB88leyo82=LQ$clP}Wh=u_TaedcGGP3&gC= zTY>oL=)o1p+Me%TPlp|M+;%zxR^mg)^99P*z1?@7oyNfNdyQ5&_Wa(FYLu zJSEOtQQUSX;f~T8NJ9$fw%rPy?vpw$8(2|Tg)~rAx2fM20rSt`rqg%3A>FOZC|xj} zJPH^AZNs0>F?lcwunwJntA+-l49NwaYFq`^#MT_*l^eE`$*8D=87y+Iq%VlE890B3 zc4x{tVs_n>GsNp=G2&W8E8?Ew3<=KUKQr-Xbw~sHGf^5QS*BT)AvS1j@ot;dUF7&+ Vc^sgCCW<&g31_Gv}cx1DCSDxSyl zM}0164NFtj7o7G+Cl4%_RA~my1GQm6i(ApQzKRdQl+) zL?K%6LTteo_|w{02}*Sz-aJ4%Q?LtSb~0HWZ2uHXUpU0aai;}8ZN-p5d8{fD4VJBt9ztyRd?Cq5v3GGtd zh^DJ*!fQKVss2@jajr|B^(C)Cs#=8O^epJ{Bs F`vV+4L^l8c literal 0 HcmV?d00001 diff --git a/base/work3/Main.java b/base/work3/Main.java new file mode 100644 index 0000000..e6f0ae0 --- /dev/null +++ b/base/work3/Main.java @@ -0,0 +1,14 @@ +public class Main{ + public static void main(String args[]){ + MyQueue queue = new MyQueue(10); + queue.push(10); + queue.push(20); + queue.push(30); + queue.push(40); + queue.push(50); + queue.printQueue(); + queue.pop(); + queue.pop(); + queue.printQueue(); + } +} \ No newline at end of file diff --git a/base/work3/MyQueue.class b/base/work3/MyQueue.class new file mode 100644 index 0000000000000000000000000000000000000000..da9377e22e1b1ec47e45a3c08b3f2543104ea53a GIT binary patch literal 1497 zcmaJ>&r@4f6#njeFL}x1Q6iH?Ajlj;<#WsB?9t**Lv9Pv9hA;oERk~t^$+;hJ3edpZCuYa#^ z0XTta2d(IhVjud%^otn~bJU?Z7RAdr9>EC*Cvi$5gAtszamIm*UNJ)v42vHT^GXC~ zCG*t?Ms1w4ab6)bmn&t93Ti^Zy5@Unx}q0k6ilyBP%z%*MR+902F0_CCA;5Y!i8Mg zS7@3Hvi{}L!mM9-+ndcWVkIZ!J{&BLmofs8?7phdI8*fIKAiIMwJbYW99zg2mzbX~ zEnZ_9zbLHl(hie;^FPAHy-FURR z{9yg&a2MTSy&f;0_p@Ad8`t$zN=*^*`<_+*Klzbjt~wNj zmgLjGL=0(e=-@+b<@2^+$kzDFkUeV8Rcg=W(%T#wcTM{OPaX7}BSNV)sJr~3kf3!~ zE~yqGjI`@CNx#Ur+{7h472kC3!$_I;VT!TDgr0yLL|8*vXyC_142@*Dhfk}CpnO)e z0(z2=!l5~}N*=2)ww7UAE3nKT88tMau+C_~ON@kI#72cSpA)S>9HkeCMuGV5KdKMx zR5y%Dc4u9cCy=b}O_dS;7VbUR&5<&qcT-mgXT48VLQ788RXJMmX^~l_R+ZVtX|+?> zA<9fpVh4ICQRtdbF}CZf&-@p?C19TIoLajE-EI};2%B%fy|SjY80>5Im$9e0sf<_| z&oQk^DlMesR+w#B>18-_TH!sNkkmJEa~IQ2M9Jp}nRb$C7nyc*Aw4*SUW}p-@1Y+b z@E=lGCt$|5F$Tj%lGCEymMQ5|Eyn7dXY^4`(vUe4uMzqIUH_I6*E*VabnN|9sg>>D pWY#SrzCO=Z_5lX@SWc7MAdX=OXE3Z;MPd8}L;Xpj3MpOE^AEnsCcOXv literal 0 HcmV?d00001 diff --git a/base/work3/MyQueue.java b/base/work3/MyQueue.java new file mode 100644 index 0000000..2124f4a --- /dev/null +++ b/base/work3/MyQueue.java @@ -0,0 +1,55 @@ +public class MyQueue{ + private int count; + private int head; + private int tail; + private int[] arr; + + public MyQueue(){ + } + + public MyQueue(int size){ + arr = new int[size]; + head = 0; + tail = 0; + count = 0; + } + + //---------------------------------------------- + + public boolean isFull(){ + return count == arr.length; + } + + public boolean isEmpty(){ + return count == 0; + } + + public void push(int value){ + if(isFull()){ + System.out.println("队列已满,不能再添加元素了!!!!"); + return; + } + count++; + arr[tail++] = value; + } + + public void pop(){ + if(isEmpty()){ + System.out.println("队列已空"); + return; + } + int temp = head; + + System.out.println(arr[head]+"出列"); + count--; + head = (head == arr.length - 1 ? head : head+1); + arr[temp]=0; + } + + public void printQueue(){ + for(int i = 0;i <= arr.length-1 ;i++){ + System.out.print(arr[i]+" "); + } + System.out.println(""); + } +} \ No newline at end of file diff --git a/base/work4/LLQueue.class b/base/work4/LLQueue.class new file mode 100644 index 0000000000000000000000000000000000000000..82de29bcff8c59b3b680e03e1a79c36186925349 GIT binary patch literal 1615 zcmaKrUvCs;6vm%-cXnrYI%SuZLQ7FVDP5*rwm@6J{&8t-wJ=+Xi)g)a+D>3_|D~NZ z)H@R|y!S%n22G5_#Kb__Z9TaEKMzLC7Uv=j_(Kegz zlQ*4D91}Y!sOE$L+h1zWD0V&V$Fh-|AR2aT!Yl z49gak0TWjw_XGyp!=L={P@zA}eti2UZlB!w{Li01YyBx45RhESsa($$eR5x)se7e0 zciqIh!coLkmX*y;%j>pbYO zgJ7?kTar%kyRK7a`?_D^<~M?NmMYB4go$mm6Tu`a?k&pdZpkgXGWWPstGN|kjYAye z3pvdS`N8bV1pg;K;a9^ZDeTL<+ydIy zxjV{LagA9!Q1|(waE#VKgjT0qf*y{WR>J4#my-_Wq~Y9eIhiS|xplC?B9;H4y(A<^$+mi3XDQcVR5|@1Ua)%Jy2r zQYnpQE%QU#M^Y}&G`h^^{S*w@$5}Qw8l7WFaUf~_-1<0(BYXzfS&O3>Wf^1KO|dOA zEXyXV)S5&j{TGhu7$Wg-Yi4)JD?zfWAj>+gJkFwI*!Twj^o`CW}#a zSV?gB9Pto|he@0zagOXGNxoc?Wyx=xU(5YhMFB4eW2=fP~oh{`s9T;bE`bv9P(v*&<+)s8d9p hCTbo%xWG0G)GT*%xQO`x%|MjR)YwdmfF}cu+`m9TGvxpP literal 0 HcmV?d00001 diff --git a/base/work4/LLQueue.java b/base/work4/LLQueue.java new file mode 100644 index 0000000..e7625be --- /dev/null +++ b/base/work4/LLQueue.java @@ -0,0 +1,82 @@ +public class LLQueue{ + MyNode head; + MyNode tail; + int count; + int maxSize; + + public LLQueue(){ + } + + public LLQueue(int size){ + maxSize = size; + head = null; + tail = null; + count = 0; + } + + public boolean isFull(){ + return count == maxSize; + } + + public boolean isEmpty(){ + return count == 0; + } + + public void push(int value){ + if(isFull()){ + System.out.println("队列已满"); + return; + } + MyNode node = new MyNode(value); + if(count == 0){ + head = node; + tail = node; + count++; + return; + } + tail.next = node; + tail = node; + count++; + } + + public void pop(){ + if(isEmpty()){ + System.out.println("队列已空"); + return; + } + if(head == tail){ + head = null; + tail = null; + count--; + return; + } + MyNode temp = head; + head = head.next; + temp = null; + count--; + } + + public void printLLQueue(){ + if(isEmpty()){ + System.out.println("队列是空的!!!!"); + return; + } + MyNode temp = head; + while(temp.next != null){ + System.out.print(temp.element+"-->"); + temp = temp.next; + } + System.out.println(temp.element); + } +} +class MyNode{ + int element; + MyNode next; + + public MyNode(){ + } + + public MyNode(int n){ + element = n; + } +} \ No newline at end of file diff --git a/base/work4/Main.class b/base/work4/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..6eee07ec1f1c61922c5f14bfea060cad18e16bed GIT binary patch literal 444 zcmYk1T}uK%7=_R5hpXe7+lTgHUU-!yBvjCa(oGNqTM}b>=UF_dSWpD-Ts3z&Y( zlXF-tub9!zSjxDfIfu=a`?u_+!%^mA(!oZVeia6+F=B(2J;rOX-=_O9{ZFarz+;Xw H{SA1(%IigZ literal 0 HcmV?d00001 diff --git a/base/work4/Main.java b/base/work4/Main.java new file mode 100644 index 0000000..f492fcc --- /dev/null +++ b/base/work4/Main.java @@ -0,0 +1,17 @@ +public class Main{ + public static void main(String args[]){ + LLQueue q = new LLQueue(5); + + q.push(10); + q.push(11); + q.push(12); + q.push(13); + q.push(14); + q.printLLQueue(); + + q.pop(); + q.pop(); + q.pop(); + q.printLLQueue(); + } +} \ No newline at end of file diff --git a/base/work4/MyNode.class b/base/work4/MyNode.class new file mode 100644 index 0000000000000000000000000000000000000000..aa43a3b9eaa9416e3abfca827ffdf04b49f7bf50 GIT binary patch literal 312 zcmYLDu}%U}5S%>@j(eVfVrQcrULlR0#Ky#gin&JENavK}an806)q& zPYa7TZ+CWPcE7$qJ^@_e#2`d3MgvC?jwAF1k(RnvR|#Y+2%WyNY}?7(bn~Rwg4U>T zMRg-+3@#oixFs#<+QR9yUgx@f$nug*I2il6S#0X>69b5kARe$g=P&%5=^paVg6oLp*Jv3r jArs?}=;bMSA8EWiJ>4Pr_jI@tn9*}j$DEE1`vBb^BS$Y5 literal 0 HcmV?d00001 -- Gitee