Тёмный

Insertion Sort | C++ Example 

Portfolio Courses
Подписаться 227 тыс.
Просмотров 28 тыс.
50% 1

An example of implementing the insertion 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...

Опубликовано:

 

4 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 49   
@MetalWhale.
@MetalWhale. Год назад
Amazing! The commented example allowed me to finally understand the algorithm. I've watched several videos, read through my textbook, and this example is by far the best illustration of an insertion sort. Thanks.
@ShyamKumar-cn9hb
@ShyamKumar-cn9hb Год назад
best explanation of code ever
@PortfolioCourses
@PortfolioCourses Год назад
I'm glad you enjoyed it! :-)
@more-uv4nl
@more-uv4nl 8 месяцев назад
amazing explanation
@musabakhtar393
@musabakhtar393 7 месяцев назад
can someone please explain the while loop area, like what is in a[ j ] or what is stored in it because I cant seem understand the whole loop specially a [ j ] and a[ j + 1 ]
@yuripanosyan5267
@yuripanosyan5267 Год назад
Sir, your explanation is clearer than the God's soul!! Thanks!
@PortfolioCourses
@PortfolioCourses Год назад
You're welcome Yuri, I'm glad you enjoyed it! :-)
@tungno7
@tungno7 Год назад
easy to understand, thanks!
@default2043
@default2043 Год назад
Very nice video! If I want to perform insertion sort in reveres order, then I need to switch "a[j] > key" to "a[j] < key", but unfortunately I will get a segmentation fault this way. Any ideas why this is and how to solve it?
@BlaqRaq
@BlaqRaq 10 месяцев назад
In the for loop, to print, put i = 7 with i >=0, then decrement i (i-) This will reverse the array numbers. There you go. Sorted.
@t6hp
@t6hp 9 месяцев назад
it's likely not due to the comparison operation (a[j] < key), but rather an issue elsewhere in your code that is causing out-of-bounds memory access. The switch in the comparison operator is indeed the correct approach to sort in descending order. Ensure that your loop indices do not cause you to access the array out of its bounds. This could happen if ScannerIndex goes below 0 and you still try to access arr[j].
@ramakrishna4092
@ramakrishna4092 Год назад
Hi sir I have one doubt in post increment in c Int a=10; a= a++ ; If I print the value of a the output will be 11 right but why the output is 10 can you pls explain this Thank you..
@PortfolioCourses
@PortfolioCourses Год назад
i = i++ is undefined behaviour in C, this answer explains better than I would be able to: stackoverflow.com/a/26895433. :-)
@jaderose2886
@jaderose2886 Год назад
I love ur vids, but I think it would be really cool if you did some operating system content. Like how to create processes and all tht kinda stuff
@PortfolioCourses
@PortfolioCourses Год назад
Thanks Jade! :-) That's something I want to cover more of one day, in particular creating processes in C.
@jonluis2647
@jonluis2647 5 месяцев назад
Best one out there👌🏼👌🏼👌🏼🫡🫡🫡🙏🙏🙏🙏
@PortfolioCourses
@PortfolioCourses 5 месяцев назад
I’m glad you enjoyed it! :-)
@gerdsfargen6687
@gerdsfargen6687 Год назад
No way! Was just doing in Java. Mind reader!
@PortfolioCourses
@PortfolioCourses Год назад
Hahaha I think it's that time of year for insertion sort! :-)
@gerdsfargen6687
@gerdsfargen6687 Год назад
@@PortfolioCourses you just reminded me of Bugs Bunny and Daffy Duck. "Insertion Season! " "Bubble Season"....fire!
@PortfolioCourses
@PortfolioCourses Год назад
😂
@yoruichi5802
@yoruichi5802 Год назад
Exact same here lol
@KrumRashkov
@KrumRashkov Год назад
I love your videos and you are a really big help with all c and c++ related topics, thank you for putting out this amazing content. However, I was wondering if you can help me with a task given by my university. I have to make an insertion sort that performs the "descent" with an anchor. This means placing the inserted element at the "bottom" of the array to save from the "descend" end condition. Do you happen to have any idea how this could be done?
@PortfolioCourses
@PortfolioCourses Год назад
I'm really glad you enjoy the videos Krum, thank you for sharing that positive feedback! :-) I'm not sure I understand the question and what the anchor would be doing in the algorithm though. Do you have the question text? Was ChatGPT or Google helpful?
@KrumRashkov
@KrumRashkov Год назад
@@PortfolioCourses hey thanks for the fast reply actually i tried running the question on gpt and phind and I also consulted with some people and no one including me seemed to understand what exactly is the question so I will ask the teacher. Thanks for reaching out though.
@t6hp
@t6hp 9 месяцев назад
I think the question is just poorly formulated by the Professor, but what's being asked here is a reverse insertion sort, if I understood correctly. The anchor here is what Kevin refers to as the key, or the element being compared to all previous elements. You really change bigger than > to less than = 0) && (arr[ScannerIndex] < anchor); ScannerIndex--) { // Move the scanned element one position to the right to make space for the anchor arr[ScannerIndex + 1] = arr[ScannerIndex]; } // Once the correct position is found or the start of the array is reached, // insert the anchor. The ScannerIndex would have moved one place left of the // insertion point, so we need to insert at ScannerIndex + 1 arr[ScannerIndex + 1] = anchor; } }
@Megha-sb2vu
@Megha-sb2vu Год назад
The example helped alot and cleared the concept even more!! Tysm 🪄
@PortfolioCourses
@PortfolioCourses Год назад
I'm glad it was helpful for you, and you're very welcome! :-)
@yaseries2004
@yaseries2004 Год назад
Thank you so much love you my dear sir,💐💐💐
@PortfolioCourses
@PortfolioCourses Год назад
Aww you’re welcome! :-)
@yaseries2004
@yaseries2004 Год назад
@@PortfolioCourses can I know that where are you from
@PortfolioCourses
@PortfolioCourses Год назад
@@yaseries2004 I am from Canada. 🙂
@yaseries2004
@yaseries2004 Год назад
Thank you for reading my comments
@yaseries2004
@yaseries2004 Год назад
You look like Henry Cavill 🤔
@4O8
@4O8 Год назад
the sorting start from the leftside or rightside?
@edensparkish
@edensparkish Год назад
Thank you!!!
@PortfolioCourses
@PortfolioCourses Год назад
You're very welcome! :-)
@FritsvanDoorn
@FritsvanDoorn Год назад
Thank you
@PortfolioCourses
@PortfolioCourses Год назад
You're very welcome Frits! :-)
@shia9101
@shia9101 11 месяцев назад
is there a pseudocode of this sir?
@PortfolioCourses
@PortfolioCourses 10 месяцев назад
There is a link to the C++ code in the video description, that might be helpful? :-)
@cseb-kathirvel2674
@cseb-kathirvel2674 Год назад
Insertion sort in 2d string is it possible,pls try this program and c program for all types of errors pls upload the program
@PortfolioCourses
@PortfolioCourses Год назад
I'm curious what you mean by "all types of errors" Kathir? :-) Can you explain more about what types of errors you would be interested in seeing covered? Compiler errors? Or other types of errors that occur at runtime?
@cseb-kathirvel2674
@cseb-kathirvel2674 Год назад
Sir your instagram I'd
@cseb-kathirvel2674
@cseb-kathirvel2674 Год назад
@@PortfolioCourseshow to all compile errors and runtime errors in c pls upload video ,Why I am asking this question?This question was very important for college students.even I write a own program that time large numbers errors coming ,that errors why coming? how to solve the error?
@cseb-kathirvel2674
@cseb-kathirvel2674 Год назад
@@PortfolioCourses user input in sertion sort in 2d string in c upload this program and explain it
@shashwatmishra4974
@shashwatmishra4974 6 месяцев назад
Time and space complexity anyone please ?
@touristofsongs4946
@touristofsongs4946 Год назад
I dont get a shit from this.
@PortfolioCourses
@PortfolioCourses Год назад
Sorry to hear that!
Далее
Selection Sort | C++ Example
9:49
Просмотров 28 тыс.
Quicksort | C++ Example
26:50
Просмотров 7 тыс.
This mother's baby is too unreliable.
00:13
Просмотров 11 млн
How Many Twins Can You Spot?
00:17
Просмотров 22 млн
how Google writes gorgeous C++
7:40
Просмотров 895 тыс.
31 nooby C++ habits you need to ditch
16:18
Просмотров 791 тыс.
Bubble Sort | C++ Example
13:20
Просмотров 26 тыс.
Learn Merge Sort in 13 minutes 🔪
13:45
Просмотров 306 тыс.
Sorting Algorithms Explained Visually
9:01
Просмотров 539 тыс.
WHY IS THE STACK SO FAST?
13:46
Просмотров 157 тыс.
Insertion sort algorithm
14:15
Просмотров 1,5 млн
10 Sorting Algorithms Easily Explained
10:48
Просмотров 64 тыс.