Selection Sort | C++ Example

Поділитися
Вставка
  • Опубліковано 13 гру 2024

КОМЕНТАРІ • 28

  • @rafa-bd7es
    @rafa-bd7es 7 місяців тому +5

    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

  • @zotheditz_7
    @zotheditz_7 29 днів тому

    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!

  • @Dmitri_17
    @Dmitri_17 Рік тому +4

    Hey! thank you so much for your work, I've finally understand how selection sort works!)

  • @Phaytann
    @Phaytann Рік тому +5

    This was a great explanation, thank you!

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      I’m glad you enjoyed it, you’re very welcome! :-)

  • @tfac277
    @tfac277 Рік тому +2

    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)

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +4

      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! :-)

    • @tfac277
      @tfac277 Рік тому

      @@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

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      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.

    • @tfac277
      @tfac277 Рік тому

      @@PortfolioCourses oh. Thank you so much

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      You're welcome! :-)

  • @MUHAMMADRASHID-fj4gi
    @MUHAMMADRASHID-fj4gi Рік тому +1

    Nice explanation sir👍

  • @kessiaeapen9406
    @kessiaeapen9406 Місяць тому

    Thank youu...you saved my day ❤

  • @vanthomias5538
    @vanthomias5538 4 місяці тому

    Is it better for performance if I use the " if (min_pos != i)" ?
    Or is it better for performances if I dont?

  • @SID-TV_MW
    @SID-TV_MW Рік тому +1

    Well explained

  • @bkly_7772
    @bkly_7772 Рік тому +1

    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!!!

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

      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! :-)

    • @bkly_7772
      @bkly_7772 Рік тому

      @Portfolio Courses thank you you really are a blessing 🙌 🙏

    • @PortfolioCourses
      @PortfolioCourses  Рік тому

      You're welcome! :-)

  • @hannah8466
    @hannah8466 Рік тому

    Thank you so much for these videos

  • @markopolo2224
    @markopolo2224 Рік тому +1

    very helpful!

  • @WinwinDesu
    @WinwinDesu 5 місяців тому

    Wakoy nasabtan🎉

  • @sammyngwenya1199
    @sammyngwenya1199 Рік тому +1

    can you please start commenting your final code as well

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +2

      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. :-)

  • @hotdogdog4314
    @hotdogdog4314 2 місяці тому

    i like ur voice