From d38eaca44d066a686e34e82b3bf4873257875840 Mon Sep 17 00:00:00 2001 From: libospinach <45868766+libospinach@users.noreply.github.com> Date: Tue, 30 Aug 2022 17:35:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A9=E7=94=A8PriorityQueue=EF=BC=8C?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=A4=9A=E4=B8=AA=E6=9C=89=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/never/basic/PriorityQueueDemo.java | 109 ++++++++++++++++++ .../java/com/never/basic/zeroOneGenerate.java | 3 +- .../com/never/basic/BitOperation.class | Bin 922 -> 925 bytes .../classes/com/never/basic/BubbleSort.class | Bin 615 -> 615 bytes .../classes/com/never/basic/CommonUtil.class | Bin 451 -> 451 bytes .../classes/com/never/basic/NRecursion.class | Bin 780 -> 780 bytes .../classes/com/never/basic/SelectSort.class | Bin 651 -> 651 bytes target/classes/com/never/basic/SortDemo.class | Bin 1093 -> 1093 bytes 8 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/never/basic/PriorityQueueDemo.java diff --git a/src/main/java/com/never/basic/PriorityQueueDemo.java b/src/main/java/com/never/basic/PriorityQueueDemo.java new file mode 100644 index 0000000..95c0a17 --- /dev/null +++ b/src/main/java/com/never/basic/PriorityQueueDemo.java @@ -0,0 +1,109 @@ +package com.never.basic; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.Comparator; +import java.util.PriorityQueue; + +/** + * @Description: + * @author: Bo Li + * @date: 2022年08月30日 10:46 + */ +public class PriorityQueueDemo { + public static void main(String[] args) { + PriorityQueue queue = new PriorityQueue<>(new ValComparator()); + int[] arr1 = {1,3,5,8}; + int[] arr2 = {2,4,5,7}; + int[] arr3 = {3,4,9}; + Node head1 = array2NodeList(arr1); + Node head2 = array2NodeList(arr2); + Node head3 = array2NodeList(arr3); + queue.add(head1); + queue.add(head2); + queue.add(head3); + Node currentNode = queue.poll(); + Node head = currentNode; + if(currentNode.next != null ){ + queue.add(currentNode.next); + } + while(!queue.isEmpty()){ + Node node = queue.poll(); + if(node.next != null){ + queue.add(node.next); + } + currentNode.next = node; + currentNode = node; + } + show(head); + } + + + + /** + * @Description: 单向链表遍历 + * @param head + * @return + */ + private static void show(Node head){ + while(head.next != null){ + System.out.print(head.val+"-->"); + head = head.next; + } + } + + /** + * @Description: 有序数组转单向链表 + * @param arr + * @return + */ + private static Node array2NodeList(int[] arr){ + Node head = null; + Node currentNode = null; + Node preNode = null; + if(arr.length ==0 || arr == null){ + return head; + } + + if(arr.length ==1){ + head.val = arr[0]; + head.next = null; + return head; + }else{ + + for(int i = arr.length-1 ; i >= 0 ; i--){ + if(i == arr.length -1){ + currentNode = new Node(arr[i],null); + preNode = currentNode; + } + preNode =currentNode; + currentNode = new Node(arr[i],preNode); + } + head = currentNode; + } + return head; + } + + @Data + @AllArgsConstructor + private static class Node{ + private int val; + private Node next; + } + /*** + * @Description: 基于Node的比较器 + * @Param: + * @return: + * @Author: libospinach + * @Date: 2022/8/30 + */ + private static class ValComparator implements Comparator{ + @Override + public int compare(Node o1, Node o2) { + return o1.val-o2.val; + } + } +} + + diff --git a/src/main/java/com/never/basic/zeroOneGenerate.java b/src/main/java/com/never/basic/zeroOneGenerate.java index f687c8c..4caebed 100644 --- a/src/main/java/com/never/basic/zeroOneGenerate.java +++ b/src/main/java/com/never/basic/zeroOneGenerate.java @@ -1,12 +1,13 @@ package com.never.basic; +import java.util.PriorityQueue; + /** * @Description: TODO * @author: Bo Li * @date: 2022年08月29日 9:13 */ public class zeroOneGenerate { - public static void main(String[] args) { int[] arr = {0,0}; for(int i = 0; i < 100000; i++){ diff --git a/target/classes/com/never/basic/BitOperation.class b/target/classes/com/never/basic/BitOperation.class index 9e7568320849c187d8dc919f2f14cf155dcef6cf..e2811675a175bbad62bcb33a4feb59219fac82a6 100644 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3mUCoVT#E zJ3BM?R&O=^e4j4>OAI_HbRF~@^aboFJ*DTBfSS$M`Q~Q%D8b63@wJg9mn1wUr$ZQT zv;FRj2_&t>lMscB-R2e&1<}$Eh`TvE?6x6YxSajJ0A+aG%BUEoFz*;tBG&bAvC=~w yEMgsu;`^GMM3K`ncaOb7w~rdCCR6`?+-g)Yfz>eo)Y0T5jibd$k!@2U(fI)vHyL^W delta 269 zcmYL?y>7xl5QM+;84Tvf{DdSDL{XZET!9-(L`Ur|y+Kg~il`7R&%itI0#uPw(9osH z8zJUQky~kIcV}nrY|nP`d-*v5V;*AyY(!Y6MA^_<<=Z^{%GaN1HeY=#Hiq(Kxn6Fj z20MIvkErbbp7*bZ9WO-k`WIllTUgbUijBDBzA?u_j)h)^3N>NNta3OQyLDk)Y%QyD(f-F&oYYf=Ioy2U>Ucj^M^HG1l-w)eUS Gc(?+0avAFY diff --git a/target/classes/com/never/basic/NRecursion.class b/target/classes/com/never/basic/NRecursion.class index ec9fb4ee2e0ed941da92abb8255d6625cd4dc7dc..ffeb10535f2fc7964d67e77ab1bf00c82982e38f 100644 GIT binary patch delta 380 zcmXAky-or_6ot>s?#{Zyf~>13prYarKLsJNBzBr$W8xbiAqHaBM9|hkOPb9-0PzvD zFvh|M@CmGJeFqETnRRY5bMDE#-@P+cQ`P>QzkdKYL{mdyL&L$QhYGedwz1=)>S9+w zb%xP!awK5Y;-6Wdqw_)k_GUc1js)ylx1KzRy;$qLoJ`P;eeALm1Pbxuv z)Vu4ou6ogB>+E7Q=uhIuwj~h8PhtEO6gbV{0_Io{hQ!-TzD40)(^JeqFT>kUwZk{d z%tH=~rk1)3$pEtI4YKnBtNaT4nTCXc@(7qY9I=FuIBousVw16K w3Z2Yk_0%*pU~`+0jbVx_W0lH`C}J&bwdoY8Buex%kaH*@#4pJL<+ODD51dRZ!~g&Q delta 379 zcmXAly-or_6otQ8mR%SYM9@`0MMdSWAVy1KjD-m{CKmQch=G{Z2-^ArG-PXId;~3w zvG4(W2rHk$f_P`mB$IRRocqn0nK%>Y_-pp@3GCCqrr8cuxp)qCrO4mm#oJ;x$s8q zrZo#Jy7(STEQimkI^BDm{v7#i2+ooq5JQ;+vKPW{IrV9k=~Ty7Wf=MH&_ck`Xj$flFdp2Il_{ur2|RlLVVo1g9g9!GMG-}J!s-i4v(obQ{ZM4Jw8|L-bj)dNZ zh-G2&cRb%7 delta 268 zcmXYrzfJ;S5X67`9mnB$!ioP;Ks(Xm3P~(9cA8jOnAo4j5Qw27K7kz-xp&aoN@L*z z7$3$L5S&llVsJ!-CR$In3t?Ynn23QxErEu;*Vn6?z%v zEeeyr1?ntmGL~5p)`~|vuSO5fo@Srk7?2j3^VS4K@|IRrFjlYD#moegNN{Aj<#% diff --git a/target/classes/com/never/basic/SortDemo.class b/target/classes/com/never/basic/SortDemo.class index 4e4d68a2351df72140f3934abc2c9d51c919d094..33b091df02e88dd874eb5952425816fc458e095a 100644 GIT binary patch delta 566 zcmYL_O-~b16o#KWLwl#g0HxJhTagM_+Nm-{DJoV#|9}e;5*Ef(Ld*~{nmW;?3*EYC zX6wSZajlENh_YkjZ}3mJHAX#mShzV~Irly9b5EQT=i&E1Uygwl?zt4X>@r1Dv*==* z#->%Ejj!prXfx4Vaky&ok_mxJmt_;KX|8Kl6#0G_h4H$=Znd|Qy!CdpJDt38H0vH4YDf3sg8KU4bg+Wl~OBcJHNiguQdfSSKad z`Hb~np+Zi!U7C#JGbz|p0$9uxD{=+as8N^Pl#3Ub5lz?plF^pwE5@>|uHCQu$M0GA zME(dZ#~i=Dlu{_UDdBjEmoo8MsSkgD$VSSfv0!HqrxwaM(#?x#TMz<)Fi^&V#Uc&) Z8N=VrEWn)91+3p#>X$fE^3eRr!awrkOJe{4 delta 604 zcmYL_y>1gx5QV>cH}=}gwd2Ib#u!8XF#ZX#^9uwMNRW^a1%;(Zhyod~qKzzrHVZ8U zyZ~C!QPEH$C^m>l>C*5FJOPh@5HP!uNHcfm?97>S&QaANTMin_X3UTv zsmSg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