In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor will share with you how to use C++ to select the k smallest number in an unordered array. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge. So share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Select the k-th smallest number from an unordered array of integers, such as KF1 is the minimum number and KFN is the maximum number. Here the array can have duplicate values!
The following is a function written by myself, write it down here to remember the traces I left!
/ / Select the k-th number in the unordered array # include using namespace std; bool failed = false; / / only consider int findnumber (int * array,int start, int end, int k) {if (array = = NULL | | start > end | | k) whose array is int.
< start || k >End+1 | | k tk) {end = f;} else {start = f + 1; tk = k-start; / / this place made a mistake, that is, it was written as k=k-start, and always found infinite loops when debugging. Later, when printing the value of k, it was found that the value of k was negative. This bug, this fault makes it possible to get the correct data in one run, but the program crashes after many runs. } len = end-start + 1; ps = rand ()% len + start;}} int main () {int array [10] = {1 cout 1, 2, 4, 1, 1}; for (int I = 0; I < 10; I + +) {cout
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.