From ea5a90004a1b1bc4566c1538f6cd3869fe73b4b6 Mon Sep 17 00:00:00 2001 From: shiququ <2187766738@qq.com> Date: Thu, 4 Aug 2022 18:01:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BAjava=E4=BB=A3=E7=A0=81=E7=9A=8428=5Fso?= =?UTF-8?q?rts=E4=B8=AD=E7=9A=84=E5=A0=86=E6=8E=92=E5=BA=8F=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=A2=9E=E5=8A=A0swap=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- java/28_sorts/HeapSort.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/java/28_sorts/HeapSort.java b/java/28_sorts/HeapSort.java index 27840493..f25b6f29 100644 --- a/java/28_sorts/HeapSort.java +++ b/java/28_sorts/HeapSort.java @@ -71,4 +71,10 @@ private static void heapify(int[] arr, int n, int i) { } } + private static void swap(int[] arr, int i, int maxPos) { + int tmp = arr[i]; + arr[i] = arr[maxPos]; + arr[maxPos] = tmp; + } + } \ No newline at end of file