Learn C++ With Me #19 - Sets

Поділитися
Вставка
  • Опубліковано 8 лют 2025

КОМЕНТАРІ • 45

  • @steeric2053
    @steeric2053 3 роки тому +66

    0:27 That is a major misstatement. In C++ `std::set`s are *ordered*, and accesses don't have a constant time complexity. For unordered sets, use `std::unordered_set`, which uses hashing to implement constant time accesses.

    • @TechWithTim
      @TechWithTim  3 роки тому +17

      Thank you for pointing that out! My mistake on that, I’m used to Python sets.

    • @fenio4689
      @fenio4689 3 роки тому +13

      @@TechWithTim please edit the video that caused me some trouble

    • @KajalSinghshine
      @KajalSinghshine 3 роки тому

      Thanks. I was confused that what is the difference between set and unordered_set.

  • @anakonda1709
    @anakonda1709 Рік тому +3

    Thank you TIm with your tutorials a passed the olympiad in Kazakhstan

  • @Dzonex_
    @Dzonex_ 8 місяців тому +2

    5:10 There is a bug that can happen when the element 'C' is located at the end of the set. The find() func returns a iterator pointing to the value that is located, end() func returns a iterator to the end of the set. However if the 'C' value is at the end and we say if it's equal to the end of the set then it will say that 'C' was not found. The correct code should be
    if(s1.find('C') != s1.end()){
    cout

  • @barrotem5627
    @barrotem5627 3 роки тому +6

    You're fluid and eloquent, well done ! Keep up the great work. 😃
    Edit : I hope fluid is an appropriate word here... I meant he is continuous, you know?
    (Please correct me 😆)

  • @ahmadb.e.k4629
    @ahmadb.e.k4629 Рік тому

    Thanks bro that is nice elaboration !

  • @dealvin
    @dealvin 3 роки тому +3

    Thank you for this videos. I hope you that do something project with c++ , basics and complex.

  • @dealvin
    @dealvin 3 роки тому +2

    More c++ videos, please.

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

    when you run the code at around the 4 minute mark, you actually DO know what order they'll be displayed in, its in reference to the ASCii table. I started playing with it when I noticed capitals came before lower case lol

  • @dilshadnajimi6955
    @dilshadnajimi6955 3 роки тому +4

    Hello Tim do u have any plan to teach gui in the advance programming?

  • @yourdadsbestfriend7101
    @yourdadsbestfriend7101 3 роки тому

    thanks tim

  • @agustinperalta336
    @agustinperalta336 7 місяців тому

    buen video kapo

  • @piyanshigupta2631
    @piyanshigupta2631 3 роки тому

    Hlo sir
    Your video are really very supportive. You are doing a appreciable work by sharing your knowledge and experience with us.
    Thanx alot

  • @zauq786
    @zauq786 2 роки тому

    Nyc Work!

  • @ethanshay7819
    @ethanshay7819 3 роки тому

    Thanks for the tutorials. It would be very helpful to beginner and intermediate projects to help with learning.

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

    I want to learn some c++ projects with you Tim. How about building some apps and games?

  • @KyranFindlater
    @KyranFindlater 3 роки тому

    can you explain in further detail why you prefer ++i instead of i++ for a loop incrementor statement? In the scope of a simple for-loop, that incrementor/end of loop statement happens at the end of the loop and due to the order it doesn't matter if you post-increment or pre-increment the variable.

    • @AlFredo-sx2yy
      @AlFredo-sx2yy 2 роки тому +8

      since he doesnt explain it, i guess i will help you out ...
      ++i just increments the value of i and returns the new value of i
      i++ has to store the value of i in a temporary variable, increment the value of i the same way ++i does and then return the temporary.
      Both of these operations are really cheap, but back in the day, every single cycle of processing power really mattered, so the small overhead i++ might have over ++i really mattered back then.
      Nowadays, there's 2 reasons as for why using i++ doesnt matter that much: because computers are more powerful and that barely affects anything with regular ints, and because modern compilers automatically optimize all of your i++'s in loops with ++i's when there is no difference between the 2, so there's no performance impact.
      The reason ++i is still prefered nowadays is because this operator can be overloaded for different classes or structs, for example, iterators. An iterator for a simple vector class for example is simply incrementing by 1 the address of a pointer so its really cheap either way and you wont notice a performance impact when looping, but there might be a class that is really complex and the ++ operator could be doing a lot more work behind the scenes. Most iterators dont really matter, but usually, the ++n implementation is slightly faster than the n++ one because it doesnt have to copy a temporary value.
      The general rule of thump is that ++i is either faster or as fast as i++ when working with custom classes or iterators for custom classes.
      A real life example of why this could matter:
      Imagine i have an "entity" class where i store a lot of information about each entity, such as a string for the name, an unsigned int for its age, some doubles for its X, Y and Z position, etc etc... If i want to store these "entities" inside of a simple list class (for example a linked list or a vector), each element im storing is of a certain custom class that occupies a lot of space in memory per member, because it has to store a lot of member variables for each entity. If i have an iterator, the ++itr will simply return a reference to the next element in the list, while using the itr++ will have to copy the element into a temporary value, because returning references to temporary values is not going to work (the temporary is temporary after all, so you really have to make a copy, you cant return a reference to that) which means im copying the whole element for each loop the iterator does if i use an itr++. For a list of ints this might not matter, but as i said, if im using a class that contains a big amount of data per member, it will slow down the program's performance.
      Here's a simple implementation of the operators n++ and ++n for an iterator for a vector class so you see what i mean:
      //this is the operator that goes ++i
      const T & operator++()
      {
      return ++ptr;
      }
      //this is the operator that goes i++
      T operator++(int)
      {
      T * temp = ptr;
      ++ptr;
      return temp;
      }
      as you can see, the operator for i++ has a lot more info inside.
      Now, putting all of this aside, let me remind you this is for custom classes. For regular ints in a for loop it doesnt really matter because as i already said, modern compilers will automatically optimize that so you can use i++ if you want if you are working with ints. If you are working with anything else, just to be safe use ++i for performance.
      Im not english so sorry if the explanation was not clear enough. I did my best i guess :P

  • @MusicalGeniusBar
    @MusicalGeniusBar 3 роки тому

    Can sets also work for classes eg if this class(person) is in this set ?

  • @tambaserchamling6375
    @tambaserchamling6375 3 роки тому +3

    Hi I am from nepal
    Someone said me c++ is not good programming language but I want to learn it and can I get job in software developer after learn c++
    I want to become software developer

    • @zombiekiller7101
      @zombiekiller7101 3 роки тому +1

      You need to learn atleast 2-3 programming languages.
      Each programming language is good in a specific task.

    • @gagan-tb2pp
      @gagan-tb2pp 3 роки тому +2

      It is a good language don't let anyone decide what you will do in the future. If you like it do it if not then it's up to you. I learned 3 languages even tho I only needed one. The more you learn the better your brain will be trained. good luck

    • @tambaserchamling6375
      @tambaserchamling6375 3 роки тому

      @@zombiekiller7101 thank you so much sir

    • @tambaserchamling6375
      @tambaserchamling6375 3 роки тому

      @@gagan-tb2pp thank you so much sir

  • @roshasper8633
    @roshasper8633 6 місяців тому

    What's the name of this program

  • @Jordan4Ibanez
    @Jordan4Ibanez 3 роки тому +1

    I think I over engineered my solution a bit
    void MyOutPutTest(){
    std::string test = "This is a test iii jj j hgahs aaaaaaaa";
    std::string find = "hello";
    std::set initialLetters;
    std::set findLetters;
    for (char const &letter : test){
    initialLetters.insert(letter);
    }
    for (char const &letter : find){
    findLetters.insert(letter);
    }
    bool allLettersInTest = true;
    for (char const &letter : findLetters){
    bool found = false;
    for (char const &secondaryletter : initialLetters){
    if (!found && letter == secondaryletter){
    found = true;
    continue;
    }
    }
    if (!found){
    allLettersInTest = false;
    break;
    }
    }
    if (allLettersInTest){
    std::cout

  • @Jfti9200
    @Jfti9200 3 роки тому

    Help me with my survey.❤
    What do you guys personally want the features of your device but it is not available yet? Or what you want to bring change in your device?
    I hope this is understandable🙏

  • @Pablex3D
    @Pablex3D 2 роки тому +1

    You just cut down a 2 hour lesson to a few minutes for me, thanks

  • @dr.merlot1532
    @dr.merlot1532 2 роки тому

    The Black Gulch.

  • @dinakarandavid8936
    @dinakarandavid8936 3 роки тому +1

    Hllo bro

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

    You didn't mention set.count();

  • @nuswe5778
    @nuswe5778 3 роки тому +1

    Helloooo

  • @johnchu869
    @johnchu869 2 роки тому

    mark

  • @fahmidurarnob2470
    @fahmidurarnob2470 3 роки тому

    You should start using '
    ' instead of endl
    😶😶

    • @KyranFindlater
      @KyranFindlater 3 роки тому

      why?
      is only a new line on linux systems, you need
      for windows. using std::cout and std::endl it allows you to write code in a platform-independant way, and depending if you compile for linux or windows or otherwise aren't sure of the target platform, letting the C Std libraries handle this for you is significantly better practice.

    • @fahmidurarnob2470
      @fahmidurarnob2470 3 роки тому

      ​@@KyranFindlater std::endl is an object that append the new line character and flush stdout buffer for this reason it takes more time to process. but '
      ' is a string of length 1 that gets append to stdout so it is faster than std::endl.

    • @FaranAiki
      @FaranAiki 2 роки тому +1

      @@KyranFindlater
      Now, now, have you found the reason why you are wrong?

  • @oskarpravst3686
    @oskarpravst3686 3 роки тому

    hey

  • @RekhaRani-mu9od
    @RekhaRani-mu9od 3 роки тому

    Hiiiiiii

  • @c4g3dB34st
    @c4g3dB34st 3 роки тому

    First

  • @pv9060
    @pv9060 3 роки тому

    Hi