In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use Java Hill sorting method". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use Java Hill sorting method".
Hill sorting method is used to sort a group of data from small to large, and the data are 69, 56, 12, 136, 3, 55, 46, 99, 88 and 25, respectively.
The whole process of Hill sorting is as follows:
Code implementation:
/ * Day 9, Hill sort * / # include # include / * Hill sort (Shell Sort) is a kind of insert sort. Also known as shrinking incremental sorting, is a more efficient and improved version of the directly inserted sorting algorithm. Hill sorting is an unstable sorting algorithm. This method is named after DL.Shell proposed in 1959. * * Hill sorting groups records according to a certain increment of the subscript, and sorts each group using the direct insertion sorting algorithm; as the increment decreases gradually, * * each group contains more and more keywords, and when the increment is reduced to 1, the whole file is divided into a group, and the algorithm is terminated. * / / * * * function name: Shsort * Parameter description: pDataArray unordered array pointer * number of iDataNum unordered data * description: Hill sort * / void Shsort (int* pDataArray Int iDateNumn) {int ijjjjjjjjjjr d D = iDateNumn / 2; / * determine the fixed increment value, set to half the length of the array * / while (d > = 1) / * increment equals 1 exit loop * / {for (I = d * *)
< iDateNumn;i++) /*数组下标从d开始进行直接插入排序*/ { /*也就是数组的第d+1个元素*/ int temp = pDataArray[i]; /*设置监视哨,元素最右边的位置*/ j = i - d; /*确定要进行比较的元素的最左边位置*/ while((j >= 0) & & (temp < pDataArray [j]) / * from back to front, find the position of a number smaller than it * / {pDataArray [j + d] = pDataArray [j]; / * data move right * / j-= d / * move d positions to the left * /} if (j! = I-d) / * there is a number smaller than it * / pDataArray [j + d] = temp / * insert pDataArray [I] * /} d = d / 2 at the determined location }} / * function name: main* parameter description: no * description: main function * / void Main (void) {int pDataArray [10] I Printf ("Please enter 10 data:\ n"); for (I = 0 [d ", & pDataArray +) scanf ("% d ", & pDataArray [I]); Shsort (pDataArray,10); printf (" sorted order is:\ n "); for (I = 0 + I < 10 printf +) printf ("% 5d ", pDataArray [I]); printf ("\ n ") System ("pause");}
The results show that:
Thank you for your reading, the above is the content of "how to use Java Hill sorting method". After the study of this article, I believe you have a deeper understanding of how to use Java Hill sorting method, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.