Sort, what's my mistake plz correct it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Sort, what's my mistake plz correct it

https://code.sololearn.com/c3m0b8jp7sQx/?ref=app

12th Dec 2021, 5:58 AM
PRIYANSHU GOYAL
PRIYANSHU GOYAL - avatar
10 Answers
+ 5
PRIYANSHU GOYAL you need to call the function in separate line than use an for loop to iterate and read the sorted array and print that with the index values. Below is the fixed code attached for your reference. https://code.sololearn.com/cUh03PQkQ1re/?ref=app
12th Dec 2021, 6:10 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 7
Vasiliy I just wrote that as general practice in sorting as sizeof is used most of the time for getting the length of array and string. I updated the code with sizeof concept and our discussion regarding size_t will help him to use those accordingly to the situation and usability ☺ ...
12th Dec 2021, 10:07 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 6
Vasiliy size_t is used more often with STL. It always return an positive range unsigned value. When we are sure that some iteration index can't be negative in that case we can use this as it's return positive range only. Here we used this for array length or sizeof array and size of array always return an size_t type value so for general iteration of this we can use size_t in place of int type..
12th Dec 2021, 6:52 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 5
Vasiliy yeah you are correct about size_t that it will takes the max memory of an object size but some thing that return the suze_t type we can use that. For an example Use size_t when dealing with the size/length of a memory object like sizeof() returns size_t type values,strlen() and length of array this all return an size_t. Here in sorting we use sizeof operator to get the elements length and size so we can use this size_t here. Both int and size_t has their pros and cons according to the place of using... https://en.cppreference.com/w/cpp/types/size_t
12th Dec 2021, 8:00 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 2
Martin Taylor, size_t is twice as large as int.
14th Dec 2021, 9:53 PM
Solo
Solo - avatar
+ 1
GAWEN STEASY What is this size_t, why not just write an int? 🤔
12th Dec 2021, 6:31 AM
Solo
Solo - avatar
+ 1
GAWEN STEASY This is exactly what I wanted to draw your attention to. If we didn’t know the size of the array, or it would change, then we would have to use sizeof in a loop instead of 5, and then perhaps it would be preferable for us to use size_t, (they are even consonant and themselves ask to work in pairs ☺️), but you Here you are comparing size_t with a very small int: for(size_t i = 0; i < 5; i++)
12th Dec 2021, 8:30 AM
Solo
Solo - avatar
+ 1
GAWEN STEASY, thanks for the answer, this is what I wanted to see, you need to start getting used to new data types ☺️
12th Dec 2021, 3:35 PM
Solo
Solo - avatar
0
Thx bro
12th Dec 2021, 6:16 AM
PRIYANSHU GOYAL
PRIYANSHU GOYAL - avatar
0
As far as I understand, size_t is used for a 64-bit system and in a 32-bit system it is useless, moreover, it takes up more cached memory than int and unsigned.
12th Dec 2021, 7:25 AM
Solo
Solo - avatar