Sort function in C++



Download 23,32 Kb.
bet1/3
Sana31.12.2021
Hajmi23,32 Kb.
#205660
  1   2   3
Bog'liq
Sort function in Cpp


Sort function in C++ | C++ Algorithm Sort

Sorting is an essential task in everyday life and Mathematics too.  Most of the time, you have to sort objects or numbers in ascending or descending order, or in even an odd series. It all depends on how you want to arrange your numbers or objects. C++ helps in the sorting process by providing a Sort() function in STL, the Standard Template Library. STL is a library which consists of predefined functions and data structure which makes it user-friendly. STL also consists of container classes and algorithms and iterators.

To learn more about the basics of Now let’s get to know about the Sort Algorithm in STL.


Sort Algorithm

Before we know more about Sort () in STL, there are a few important points we need to know about Sort ().



  1. In C++ STL, we have a sort function which can sort in increasing and decreasing order.

  1. Not only integral but you can sort user-defined data too using this function.

  1. Internally it uses IntroSort, which is a combination of QuickSort, HeapSort and InsertionSort.

(This is important as it occurs internally and no one knows about it.)

  1. By default, it uses QuickSort, but if QuickSort is doing unfair partitioning and taking more than N*logN time, it switches to HeapSort. When the array size becomes very small, it switches to InsertionSort. 

(This conversion and checking occurs internally and is not very popular to people)

  1. We can use parallel execution policy for better performance.

(To invoke this policy all you have to do is pass only one parameter which is std::sort(std::execution::par, Vec.begin(),Vec.end());

You have to mention the start and the end, and it will take care of the rest. You don’t have to do any multithreading coding to get a good result.



Note: There are a few situations where you cannot use parallel execution policy when you have data arrays. There are so many other algorithms in the algorithm section of STL for it. You can also do parallel processing.)


Download 23,32 Kb.

Do'stlaringiz bilan baham:
  1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish