I'm Brazilian, and I'm here to thank you. In my language (Portuguese), I couldn't find an explanation for this topic. But on your channel, I found the whole matter
i dont know if my opinion is wrong but i think in the swap step, we don't really need to add more if statement , we can write it imediately after min_pos = j ( in the same if statement) because when min_pos = j , it's mean min_pos absolutely different from i, and we need swap when min_pos = j ( sorry for my bad english)
I'm not sure if I understand your comment correctly or not. But in some sense that last if condition is optional, yes. We could take it out and just do the swap. And if min_pos == i then the algorithm will still work, we will just be (sometimes possibly) swapping an element with itself. The reason we don't do this is that swaps/assignments are much more "expensive" operations for the CPU to do than comparisons. It's more efficient to compare that min_pos != i before doing the swap than to just do the swap every time without checking, because comparisons are "fast" for the CPU to do. So you'll find all the sources online will implement the algorithm in this way. Hopefully this helps! :-)
@@PortfolioCourses Thanks! it's help me so much. But i think, when we use more if statement, it'll be Comparison + assignment operation ( cause it's If+ Swap ), but when we swap in the same if statement, i'll be just assignment. I think We must swap when min_pos = j so we don't need comparison. Sorry if i may have made some mistakes
I'm not sure I understand, but I can say that we don't always "need" to swap, when min_pos == i, we don't need to swap because we are just swapping the element with itself at that point.
Hey portfolio, I have an assignment whre i have to take peoples names and salary from a .txt file and orientate it as first name, last name, and their new salary increase by what ever percent increase it is and put it into a new file. Im having trouble figuring out how to use a while loop so i dont have to go one by one inputting each name and each salary increase. If you have any previous videos or know anywhere that could help me with this problem I would greatly appreciate it. Thanks!!!
I have a bunch of C++ file access videos each with related code that might give you some ideas: www.youtube.com/@PortfolioCourses/search?query=C%2B%2B%20file. Some of those examples include using a loop to read each line of the file... you could take the number, multiple it by the percentage increase, and write it to the other file in the loop body (if I'm understanding the problem correctly). But I don't have a solution to this specific problem or know where you might find one. Good luck on your assignment! :-)
I don't comment the code in the videos because that would make the videos too long, but if you click the link in the description of the videos the code is commented on GitHub where it is stored: github.com/portfoliocourses/cplusplus-example-code/blob/main/selection_sort.cpp. :-)
I'm Brazilian, and I'm here to thank you. In my language (Portuguese), I couldn't find an explanation for this topic. But on your channel, I found the whole matter
i'm computer engineering student and i am so blessed that i found your channel, helping me a lot with my studies. Thankyou so much bro!
Hey! thank you so much for your work, I've finally understand how selection sort works!)
This was a great explanation, thank you!
I’m glad you enjoyed it, you’re very welcome! :-)
i dont know if my opinion is wrong but i think in the swap step, we don't really need to add more if statement , we can write it imediately after min_pos = j ( in the same if statement) because when min_pos = j , it's mean min_pos absolutely different from i, and we need swap when min_pos = j ( sorry for my bad english)
I'm not sure if I understand your comment correctly or not. But in some sense that last if condition is optional, yes. We could take it out and just do the swap. And if min_pos == i then the algorithm will still work, we will just be (sometimes possibly) swapping an element with itself. The reason we don't do this is that swaps/assignments are much more "expensive" operations for the CPU to do than comparisons. It's more efficient to compare that min_pos != i before doing the swap than to just do the swap every time without checking, because comparisons are "fast" for the CPU to do. So you'll find all the sources online will implement the algorithm in this way. Hopefully this helps! :-)
@@PortfolioCourses Thanks! it's help me so much. But i think, when we use more if statement, it'll be Comparison + assignment operation ( cause it's If+ Swap ), but when we swap in the same if statement, i'll be just assignment. I think We must swap when min_pos = j so we don't need comparison. Sorry if i may have made some mistakes
I'm not sure I understand, but I can say that we don't always "need" to swap, when min_pos == i, we don't need to swap because we are just swapping the element with itself at that point.
@@PortfolioCourses oh. Thank you so much
You're welcome! :-)
Nice explanation sir👍
Thank you, I'm glad to hear you enjoyed it! :-)
Thank youu...you saved my day ❤
Is it better for performance if I use the " if (min_pos != i)" ?
Or is it better for performances if I dont?
Well explained
Hey portfolio, I have an assignment whre i have to take peoples names and salary from a .txt file and orientate it as first name, last name, and their new salary increase by what ever percent increase it is and put it into a new file. Im having trouble figuring out how to use a while loop so i dont have to go one by one inputting each name and each salary increase. If you have any previous videos or know anywhere that could help me with this problem I would greatly appreciate it. Thanks!!!
I have a bunch of C++ file access videos each with related code that might give you some ideas: www.youtube.com/@PortfolioCourses/search?query=C%2B%2B%20file. Some of those examples include using a loop to read each line of the file... you could take the number, multiple it by the percentage increase, and write it to the other file in the loop body (if I'm understanding the problem correctly). But I don't have a solution to this specific problem or know where you might find one. Good luck on your assignment! :-)
@Portfolio Courses thank you you really are a blessing 🙌 🙏
You're welcome! :-)
Thank you so much for these videos
You're very welcome! :-)
very helpful!
I'm glad you found it helpful! :-)
Wakoy nasabtan🎉
can you please start commenting your final code as well
I don't comment the code in the videos because that would make the videos too long, but if you click the link in the description of the videos the code is commented on GitHub where it is stored: github.com/portfoliocourses/cplusplus-example-code/blob/main/selection_sort.cpp. :-)
i like ur voice