Bubble Sort | C Programming Example

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ต.ค. 2024
  • An example of implementing the bubble sort algorithm in C. Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!
    Animation Source: en.wikipedia.o...
    Animation License: creativecommon...

ความคิดเห็น • 169

  • @ngl_soloqueue
    @ngl_soloqueue ปีที่แล้ว +55

    dude is speaking in most understandable language

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +7

      I’m glad you found the language understandable Doniyor! :-)

  • @intifadayuri
    @intifadayuri ปีที่แล้ว +17

    As a software engineering student we're kinda forced to learn java (at least in my school). But I'm way more interested in C so here I am. Love your videos, you are good at teaching 😊

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +7

      Thank you so much for the kind words Yurika, I'm really glad to hear you love the videos. :-) I like Java... but there's something about the simplicity and purity of C that I really love.

  • @OCEAN-fc9wl
    @OCEAN-fc9wl 2 ปีที่แล้ว +27

    Thank you! I had a hard time understanding the code of bubble sort until I stumbled upon this video! Very well explained.

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      I'm glad to hear it was helpful, and thank you! :-D

    • @dwivedys
      @dwivedys ปีที่แล้ว

      I agree - this is a brilliant explanation!

  • @BenvelMusic
    @BenvelMusic ปีที่แล้ว +7

    I'm going through the CS50X course and your C lessons are the perfect addition to fill the gaps that CS50X has. CS50 + this are perfect companions.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +3

      That's excellent to hear that, thanks so much for sharing that feedback. CS50X is such an excellent resource that I'm happy someone familiar with it thinks these videos make a perfect companion. 🙂

    • @BenvelMusic
      @BenvelMusic ปีที่แล้ว +2

      @@PortfolioCourses so CS50 is really a great resource but the main complaint is that it leaves a lot of gaps for people who learn online instead of actual Harvard and there’s a huge gap between lecture , supplemental materials and labs and psets. So good job 👏 your course is extremely helpful in a way it’s broken down compared to other stuff I looked through:)
      I can easily make a playlist putting your stuff together with their stuff as for one comprehensive course :)

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +2

      @@BenvelMusic That's awesome. 🙂 I wonder if *I* should make that playlist then and share it with my viewers, "CS50: Gaps Filled" or something like that haha...

    • @BenvelMusic
      @BenvelMusic ปีที่แล้ว

      @@PortfolioCourses I bet you could do it better than me... But it would be a great help for students who are struggling with the assignments after watching lectures and shorts plus it's a great marketing move to get traffic ;)

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      Haha that's why I may try to do it!

  • @persfallow6522
    @persfallow6522 6 หลายเดือนก่อน +1

    I've been searching for the optimized version of the bubblesort algorithm for some days, you posted this video explaining it in a very simple and complete form. I'm glad to have found your channel, i will denitively watch all your c tutorial now, you explain better than any programming profesor i've ever had at the university.
    (Sorry for my bad English, english is not my native language)

    • @Acksakal
      @Acksakal 4 หลายเดือนก่อน +1

      Pls. stop apologizing for smth that is not under your control. It's actually irritating people. I understand why you did this, English is not my first language as well, so I truly truly understand why one would say smth silly like that, but trust me you don't have to.

  • @Learn_Master
    @Learn_Master 9 หลายเดือนก่อน +5

    For those who haven't discovered still this channel on yt. They are missing treasure ❤

  • @logos_42
    @logos_42 ปีที่แล้ว +4

    Great Again: How to Transform a Complex Topic into Clear and Efficient Explanations. 🙏

  • @shamalpha2202
    @shamalpha2202 ปีที่แล้ว +1

    i bet no one can explain like this ........i am literally in the other world..........thanks to portfolio courses and the owner...keep posting more concepts..

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      You're welcome, I'm glad you enjoyed the video! 🙂 You might like these C programming playlists as well:
      Tutorials: th-cam.com/video/sepK5w4Uep0/w-d-xo.html
      Examples: th-cam.com/video/gq_ZXCuRhU4/w-d-xo.html

  • @publicstaticvoid1010
    @publicstaticvoid1010 8 หลายเดือนก่อน

    Taking a moment to thank you.
    I came from other videos (much more famous ones too) and they would only explain how the sorting algorithm works, but not the code. They would just write it without breaking it down. But, you did this! It's freaking amazing. I'm not even familiar with C but properly understood every single thing in this video. Awesome resource, much better than the other ones I've checked out so far.

    • @PortfolioCourses
      @PortfolioCourses  8 หลายเดือนก่อน

      Thank you for the positive feedback, I appreciate it. :-) One of my big goals is to explain what is happening "in the code" by breaking it down step-by-step, so it's really great to me that you enjoyed that.

    • @publicstaticvoid1010
      @publicstaticvoid1010 8 หลายเดือนก่อน

      @@PortfolioCourses No problem! You're helping many people understand the underlying programming concepts. Have a great one :)

  • @hxhchimeraantarc2268
    @hxhchimeraantarc2268 ปีที่แล้ว +1

    I was about to say isn't doing nested loop ineffective but u covered it. nice video!!

  • @vaporr5929
    @vaporr5929 2 ปีที่แล้ว +2

    Extremely well explained!! Came from Bro-code's channel and had to find an explanation for bubble sort. Subscribed and liked. Thank you for your guidance Kevin!

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      You're welcome, and thank you for the kind words! 🙂 And welcome aboard!

  • @navidradiat9876
    @navidradiat9876 2 ปีที่แล้ว +7

    Thanks for the tutorial, you went straight to the point which I liked very much and you explained everything clearly. I was really having problems understanding the swapping part at first until I found your video, and I'm thankful for that. Gotta say, you're pretty underrated man. I hope more people will find out your tutorials. Keep up the good work!

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      Thank you very much for the positive feedback Navid, I really appreciate the kind words. I hope over time more people find the channel too! :-)

  • @christopheanfry2425
    @christopheanfry2425 ปีที่แล้ว +3

    Thank you so much for tour content, doing cs50 with your clear explanations it helps a lot. Very well explained.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      You're welcome Christopher, I'm glad the explanations have been helpful for you! :-)

  • @t6hp
    @t6hp 9 หลายเดือนก่อน

    I quickly grasped the basic bubble sort but struggled with its optimizations until I saw your video. Your clear explanation and unique syntax really helped. Thanks a lot! Could you consider making a LeetCode problem series? Your intuitive approach would be a great fit. Cheers from Egypt.

  • @fifaham
    @fifaham ปีที่แล้ว

    Thank you Kevin, that was very smart optimization. As a developer I like to peek into your videos to learn your tricks that are easy to implement but need an expert like you to guide us to them. You make a great mentor for developers and professionals.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      Thank you for the support Firas! :-)

    • @fifaham
      @fifaham ปีที่แล้ว

      @@PortfolioCourses th-cam.com/video/bAjJmg7itl4/w-d-xo.html

    • @fifaham
      @fifaham ปีที่แล้ว

      @@PortfolioCourses I placed your link in the video title, if not Ok then I will remove. Please let me know.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      That's cool, thank you for making that and sharing that Firas! :-)

  • @ryanprasad2090
    @ryanprasad2090 ปีที่แล้ว

    I was trying to get ChatGPT to explain the inner and outer loops to me. Your video has it beat. Thank you for making this!

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +2

      You’re welcome! :-) And I worry sometimes ChatGPT could put me out of a job so it’s great to hear that too.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      Thanks for the donation too by the way I just saw that now, much appreciated! :-)

  • @ronsalife
    @ronsalife 7 หลายเดือนก่อน

    Your channel is saving my college degree!!

    • @PortfolioCourses
      @PortfolioCourses  7 หลายเดือนก่อน

      Aww I’m so glad it’s helping you out, and good luck with your degree, you’ve got this! :-)

  • @gayanishanka9775
    @gayanishanka9775 ปีที่แล้ว

    This is the best bubble sort explanation with everything related to it. and the optimization part was so useful. like reading a book

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Thank you so much Gayan for the positive feedback! :-) I'm so glad to hear you enjoyed it.

  • @ericcheng8808
    @ericcheng8808 2 ปีที่แล้ว +2

    Very clear and useful! Helped me a lot, better than a lot videos on TH-cam. Love the step by step explanation and you speaking speed. Hope to see more of your video coming! Again, thanks!

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Thank you very much Eric! We've got lots more videos to make, and a couple hundred C programming TH-cam videos listed on our channel already. :-) You might like the Insertion Sort, Quicksort, Merge Sort and Selection Sort videos too!

  • @SarahA97
    @SarahA97 ปีที่แล้ว

    you are amazing!
    you explained everything in the perfect order. i understood from the first time with zero confusions.
    thank you so much.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      You're very welcome Sarah, I'm glad to hear the explanation was helpful for you! :-)

  • @ripeveryday5607
    @ripeveryday5607 3 หลายเดือนก่อน

    thank you man i have exams tomorrow and you helped me

    • @PortfolioCourses
      @PortfolioCourses  3 หลายเดือนก่อน +1

      You’re very welcome, and good luck on your exams! :-)

  • @_RahmaF
    @_RahmaF 2 ปีที่แล้ว

    You are the best by far and I'm not exaggerating when I say that.
    Thank you very much for everything, keep going 👍👍

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      You're welcome! 🙂 And thank you very much for the kind words and encouragement!

  • @ibrahimsaber9808
    @ibrahimsaber9808 ปีที่แล้ว

    very useful, i like you give an explanation for each section of code you write
    Thanks alot

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      You're welcome! :-) I'm really glad to hear hat you like the way the code is explained.

  • @tuomasbazzan1523
    @tuomasbazzan1523 3 ปีที่แล้ว +3

    thanks my dude this was very useful

  • @Thecurlygirly-wh
    @Thecurlygirly-wh 2 ปีที่แล้ว

    WOW! u r amazing!
    Im watching this videos from Israel,you'r so clearly!
    thank you sooo much!

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      You’re welcome! Glad to hear you enjoy the video! :-)

  • @MrDelliSanti
    @MrDelliSanti ปีที่แล้ว

    Thank you very much. You made the temp variable very understandable!

  • @slavenpenava5413
    @slavenpenava5413 ปีที่แล้ว +1

    Second time watching this video after failing my first programing 1 exam and after taking programing course in c++ so many things are clicking for me while relearning c for my redo exam and now i finally understand why so many things are the way they are even the simple bubble sort that before confused tf out of me now looks so simple and i understand why for loops indexes and swaps are like that.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      Awesome, I'm glad to hear your understanding of these concepts is getting better, keep going, and good luck on your redo exam Slaven! :-)

    • @slavenpenava5413
      @slavenpenava5413 ปีที่แล้ว

      ​@@PortfolioCoursesmanaged to get 55%, much less than I was hoping for but it's still a passing grade although it could've been more if I remembered how to do string palindrome check with recursion

    • @t6hp
      @t6hp 9 หลายเดือนก่อน

      This is a bit too advanced for someone studying programming 1, to be honest. Sorry about that man. I'm trying to change my career and do a 2-year diploma, this stuff only came up in Algorithms 1 and Data Structures 1 in my second year.
      Don't give up, you'll get there!

  • @noligrutas
    @noligrutas 11 หลายเดือนก่อน

    Also coming from CS50x. Thanks so much for the help!

  • @dandesgeorge
    @dandesgeorge 3 หลายเดือนก่อน

    the most usefull video on this topic👑👑👑👑

  • @freelance-writer
    @freelance-writer 2 หลายเดือนก่อน

    great explanation!

  • @najdadgc02
    @najdadgc02 2 ปีที่แล้ว +3

    the best explnation i could find so far! my professor said bubble sort is bad is that true or can i still use it?

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      Bubble sort isn’t something people use in the real world because there are faster algorithms we can use instead, like Quicksort. So it’s not really “bad” so much as other better alternatives exist. :-) But it’s still very popular to learn bubble sort because it helps us learn about algorithms.

  • @muhammeddikal8551
    @muhammeddikal8551 ปีที่แล้ว +1

    Thanks a lot, perfect explanation.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

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

  • @justcurious1940
    @justcurious1940 ปีที่แล้ว +1

    Thank u Kevin, great video this is the same code but using for loop and break statement instead of do while loop, I'm not sure if they are the same when it comes to performance :
    int array[] = {4,1,-6,9,5,66,-99,0,6358,-58624};
    int length = 10;
    bool flag = true;
    for(int i = 0 ; i < length ; i++){
    for(int j = 0 ; j < (length-1-i) ; j++){
    if(array[j]>array[j+1]){
    int temp = array[j];
    array[j] = array[j+1];
    array[j+1] = temp;
    flag = false;
    }
    }
    if(flag) break;
    }
    for(int i = 0 ; i < length ; i++){
    printf("%d\t",array[i]);
    }

  • @zahidhossainbhuiyan488
    @zahidhossainbhuiyan488 2 ปีที่แล้ว +1

    just 10 seconds into the video and that's a great voice there ...

  • @heartfraud
    @heartfraud ปีที่แล้ว

    You have a great voice. Thank you for this video!

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Thank you for the kind feedback, and you're welcome! 🙂

  • @ramimehyar481
    @ramimehyar481 ปีที่แล้ว

    Excellent explanation, however, if you use (length - i) in the inner loop instead of (length - 1) you will iterate less, and save time. This way it will not iterate over the upper edge of the array again and again, since that the upper edge will be sorted quicker by simply dragging the digit down over time.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Thanks Rami! In the first part of the video a completely non-optimized version is covered for explanation purposes, the optimized version is covered later in the video. :-)

  • @drago-ig6ms
    @drago-ig6ms ปีที่แล้ว +1

    the best in the net!!!

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Thank you very much for the positive feedback, I’m glad you enjoyed the video! :-)

  • @mrdarbab
    @mrdarbab 8 หลายเดือนก่อน

    we learned this on the c64 in school. and the divide and conquer.

  • @JH-ux1re
    @JH-ux1re 2 ปีที่แล้ว

    Thank you so much! Eventually I understood what bubblesort means!

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      You’re very welcome! I’m glad to hear you figured out bubble sort. :-D

  • @Jorge-ni9pj
    @Jorge-ni9pj ปีที่แล้ว

    Thats a gread video, keep up the good work. Nice lessons!

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Thank you very much, I'm glad you liked it! :-)

  • @shashumgaclownemoji
    @shashumgaclownemoji 2 หลายเดือนก่อน

    Thanks you explained it well

  • @majidelmardouli7174
    @majidelmardouli7174 ปีที่แล้ว

    Clear and simple thanks a million

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

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

  • @youtubeuser2352
    @youtubeuser2352 ปีที่แล้ว

    I am very much comfortable doing for loop so here's what I did:
    void bubbleSort(int *arr, int count){
    int i, j, temp, counter = 0;

    //This is to traverse the array from left to right
    for(i = 0; i < count; i++){
    counter++;

    //This is to compare the array
    //When you do a bubble sort, the element with the biggest value will be moved to the last index
    //So no need to compare until the last index when you traverse hence the counter
    for(j = 0; j < count-1-counter; j++){
    if(arr[j] > arr[j+1]){
    temp = arr[j];
    arr[j] = arr[j+1];
    arr[j+1] = temp;
    displayArr(arr, count);
    }
    }
    }
    // displayArr(arr, count);
    }

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Looks good! :-)

    • @youtubeuser2352
      @youtubeuser2352 ปีที่แล้ว

      ​@@PortfolioCoursescheers!
      I saw you have recursion and text as well as binary files. Will dig into those these coming weeks.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      @@youtubeuser2352 Cool! 🙂

    • @justcurious1940
      @justcurious1940 ปีที่แล้ว +1

      Wait, it's wrong bro, u should put counter++ after the inner loop which is the same as using the i (variable) 🙃, sorry I tested your code just out of curiosity 🙃.

    • @youtubeuser2352
      @youtubeuser2352 ปีที่แล้ว

      @@justcurious1940Hi it's great you tested it out. It worked in my end but will test out your feedback!! I hope this YT channel starts a coding club where members can teach one another. Cheers!!

  • @baboucarrgibba9336
    @baboucarrgibba9336 2 ปีที่แล้ว

    thank you so much, the explanation was perfect .

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      You’re welcome Baboucarr! :-) And thank you for the kind feedback.

  • @miguelcosta4450
    @miguelcosta4450 ปีที่แล้ว +2

    I don't understand the bool swapped! When the condition is not happens because a[j] is high... Swapped will never be true and the program stop working?

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Yes Miguel, it sounds like you've got it. When swapped is never set to true, that means we never found any out of order elements, and in that case we *want* the program to stop working because the array must be sorted. :-)

  • @adamsetterberg5223
    @adamsetterberg5223 2 ปีที่แล้ว +1

    First thing Great video!

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      Yes, we have a video on filling an array with random numbers here: th-cam.com/video/5OFLit1Zf-Q/w-d-xo.html. You could use this technique to sort random numbers. You may find this video interesting too: th-cam.com/video/3jnrbtoWgDo/w-d-xo.html.

  • @kienluu2910
    @kienluu2910 หลายเดือนก่อน

    Thank you very much!!

  • @henrytzuo8517
    @henrytzuo8517 18 วันที่ผ่านมา

    Thank you so much!!

  • @BigBoss-rh8mz
    @BigBoss-rh8mz ปีที่แล้ว

    just need some clarification...please correct me if i am wrong but i believe the outside for loop only needs to be iterated "length - 1" times. for example, if sorting in ascending order and "0" happens to be at a[9], then it will take "length - 1" or 9 iterations to get "0" to a[0].
    by the way, a CS50 companion playlist would be great as others have mentioned

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      That's true, though as shown in the video we can optimize it much more than this by stopping the loop when no swaps occur. :-) I'm actually not *super* familiar with CS50 beyond know what it is... maybe one day I can make a playlist, or if someone else can pull together a playlist of videos that pair well with CS50 that would help too.

  • @abhivish2017
    @abhivish2017 2 ปีที่แล้ว

    Wow.. well explained.. thankyou so much..

  • @aizen1101
    @aizen1101 2 ปีที่แล้ว

    wow. this video is just great!

  • @kaltube4817
    @kaltube4817 2 ปีที่แล้ว +1

    well done

  • @robf5550
    @robf5550 2 ปีที่แล้ว

    This is soo good thank u!!

  • @ardeltiocojefflauron8882
    @ardeltiocojefflauron8882 ปีที่แล้ว

    Thank you so much you saved me

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      You're very welcome Ardel, I'm glad to hear the video helped you out! :-)

  • @dilhyderstudios8569
    @dilhyderstudios8569 2 ปีที่แล้ว

    Tq so much❤️ it is easy to understand

  • @NikitaSafronov-y6i
    @NikitaSafronov-y6i 2 ปีที่แล้ว

    The best! As usual

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Thank you… as usual! :-)

    • @NikitaSafronov-y6i
      @NikitaSafronov-y6i 2 ปีที่แล้ว

      @@PortfolioCourses Sir, are you a Professor/Teacher at some Uni or College? Maybe used to be. =)

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      @@NikitaSafronov-y6i Yes, I teach at both a College and University in Canada. :-)

  • @Ryokans
    @Ryokans 2 ปีที่แล้ว

    LOVE YOU!!

  • @tarikahmad4749
    @tarikahmad4749 ปีที่แล้ว

    you are so so good brother

  • @partoffans5849
    @partoffans5849 หลายเดือนก่อน

    dear , when you make last change on swapped , the program when get to not swapping will end the do-while loop what if after the not swapped pair there is unsorted elements right ?

  • @dostseferoglu6853
    @dostseferoglu6853 2 ปีที่แล้ว

    what a nice tutor,al

  • @dexdox_startups
    @dexdox_startups ปีที่แล้ว

    i cant thank you enough !!!!!!

  • @mayankbadodiya5353
    @mayankbadodiya5353 ปีที่แล้ว

    thank you so much sir

  • @natb007
    @natb007 2 ปีที่แล้ว

    Thank you so much!

  • @iceplayer3722
    @iceplayer3722 6 หลายเดือนก่อน

    Iwant to know how to sort numbers in lottery, because its big problem for me.

  • @خالدالناشري-د5ز
    @خالدالناشري-د5ز 2 ปีที่แล้ว

    Goood job
    Keep going on

  • @nub8312
    @nub8312 ปีที่แล้ว

    Great tutorial but what if in 10:08 we use i < (length - 1) instead of i < length

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      That will work too. :-) The best way that we want to optimize the outer loop is covered towards the end of the video. Using length -1 will save us one iteration of the inner loop, but checking if a swap occurred can save us many, many more for large lists.

    • @nub8312
      @nub8312 ปีที่แล้ว

      Yea, that was is much better. Thanks :)

    • @nub8312
      @nub8312 ปีที่แล้ว

      @@PortfolioCourses oh and btw did you also make a video about the "max_repeating_element" in an array. Like in this int numbers[] = {1, 2, 3, 2, 1, 3, 1, 2, 3, 1}; the Maximum Repeating Element is 1

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Yes I have a video on that topic here: th-cam.com/video/VnsmgHEZiLA/w-d-xo.html. :-)

  • @velenvskaelhas
    @velenvskaelhas 2 ปีที่แล้ว

    For the second for loop can you do "j = i+1" and then remove the "j + 1" from the if statement? or does the nested for loop have to be "j = 0"?

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      Great question! :-) It does have to be j = 0. The problem is that each "run" of the inner loop only swaps elements that are next to each other and are unsorted. It doesn't guarantee that, for example, the first portion of X elements in the array is sorted after Y runs, or anything like that. Algorithms like insertion sort and selection sort work like that, but not bubble sort.

    • @velenvskaelhas
      @velenvskaelhas 2 ปีที่แล้ว

      @@PortfolioCourses ah, thanks for the info and quick reply!

  • @mr.fantastic3827
    @mr.fantastic3827 ปีที่แล้ว

    Why is it i < length and not i

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Great question! It’s because arrays are zero indexed in C. So if we have an array of length 3 the indexes for the array are 0, 1 and 2. So if we kept the loop going until i equals length, we would be using the index 3, which is one past the end of the array. :-)

  • @stpdaz
    @stpdaz 5 หลายเดือนก่อน

    Shout-out boss

  • @natb007
    @natb007 2 ปีที่แล้ว

    Danke!

  • @marbles5590
    @marbles5590 2 ปีที่แล้ว

    Your lessons are nice, but I'm still having a hard time absorbing such things.

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      Algorithms like bubble sort are a level up in difficulty from learning the language basics, so I would say it’s normal for it to be hard to absorb them. :-)

  • @colinmaharaj
    @colinmaharaj ปีที่แล้ว +1

    This seem not right

  • @odys1516
    @odys1516 2 ปีที่แล้ว +1

    its incorrect in c language

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      What is incorrect? The code is posted here, it should work: github.com/portfoliocourses/c-example-code/blob/main/bubble_sort.c

  • @quanloithanh3934
    @quanloithanh3934 2 ปีที่แล้ว

    😍😍😍

  • @edward3105
    @edward3105 2 ปีที่แล้ว

    Man this look hard,why my Iq is so low? Why I can't change that? :(

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Coding is tough for most people, and for a long time too unfortunately. If you keep at it, it can start to get easier though. :-) Sometimes the trick is to make sure you know all the required background concepts first. So before trying to learn bubble sort, I would try to learn about loops, if-statements, variables, etc, first. Maybe try starting off with this course for beginners first: th-cam.com/video/ssJY5MDLjlo/w-d-xo.html. :-)

    • @edward3105
      @edward3105 2 ปีที่แล้ว

      @@PortfolioCourses I understand the if,while,for statements but it's hard for me to solve problems since I don't have any ideas how to solve it.I measured my IQ it's 125,should I try to continue?I graduated Computer Science but mostly I copied to exams and now I am trying to learn embedded systems.Should I just watch tutorials or should I start writing code?

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      @@edward3105 I wouldn't worry about your IQ either way. :-) It's less about "IQ" and more about "learning how to learn". Learning how to solve programming problems is less about IQ and more about having a large amount of experience seeing how different problems are solved... once you understand how to solve many problems, it gets easier to understand further problems. But it takes a long, long time, and it's definitely not easy. But if you keep at it, it will get better. I would recommend both watching tutorials AND trying to write code. Maybe for each topic you wish to learn watch a tutorial, and then try to write code.