In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Get the Nth value in the array, still use the code description, the algorithm refers to the idea of quick sorting, see the code notes for details.
# include # include ".. / pub/pub.h" / / tmparr: array to be processed / / counter: number of array elements / / n: arrange from small to large, nth number (count from 0) static int quicksort_nth_recursion (int tmparr [], int counter,int n) {/ / DEBUG: array information / / print_array (tmparr,counter); / / take any value and find the position of the value int pos = 0 Int randompos = rand ()% counter; / / moves the selected value to the first location swap (tmparr,0,randompos); for (int item1% counter) If the traversal element is less than the selected value, add the pos to the location where the pos is located / / after the loop is completed, the number that is less than the randomly selected value will be on the left side of the pos, and those greater than or equal to the selected value will be on the right side of the pos (tmparr [I] < tmparr [0]) {/ / if you traverse the swap (tmparr,++pos,i) }} / / printf ("value =% d counter =% d return tmparr target =% d\ n", tmparr [0], counter,n,pos); / / move the selected value to where it should be swap (tmparr,pos,0); if (pos = = n) return tmparr [pos] / / Recursive processing if (pos < n) / / in the array on the right, quicksort_nth_recursion (tmparr+ (pos+1), counter- (pos+1), n-(pos+1)); else// in the array on the left quicksort_nth_recursion (tmparr,pos,n);} void main (void) {/ / Parameter: first / middle / last int pos [3] = {1CoV 0 0}; int result = 0 Int arr [] = {4 sizeof (arr) / sizeof (int); pos [1] = (counter+1) / 2 pos / median pos [2] = counter;// maximum for (int I = 0 * I < 3 * ibis +) {result = quicksort_nth_recursion (arr,counter, posi]-1) Printf ("- The No.%d result is% d -\ n", pos [I], result);} printf ("- -\ n"); int arr2 [1
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.