Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Java merge sort and quick sort

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "Java merge sort and how to realize quick sort". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

merge sort

//merge sort public static void mergeSort (int[] arr) { //Create temporary data to store data int[] temp = new int[arr.length]; mergeSort(arr, 0, arr.length - 1, temp); } private static void mergeSort(int[] arr, int left, int right, int[] temp) { if (left < right) { //if the difference between the starting subscript and the ending subscript is less than 1, do nothing int mid = (left + right) / 2; mergeSort(arr, left, mid, temp); //group, divide the left into groups, recursively call to sort mergeSort(arr, mid+1, right, temp); //divide the right into groups merge(arr, left, mid, right, temp); //merge left and right groups } } private static void merge(int[] arr, int left, int mid, int right, int[] temp) { int i = left; //define left pointer int j = mid + 1; //define right pointer int t = 0; //pointer to temp temporary array while (i

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report