Today's Learn: Bubble Sort and Middle Node
Hey guys,
I focused on the two main concepts today-Bubble Sort, and how to find a middle node in a LinkedList.
Bubble Sort:
Bubble Sort is a very simple sorting algorithm in that we go through the list over and over again, comparing and swapping adjacent numbers until everything is in order. It's called "bubble" because the biggest numbers slowly "bubble up" to their correct positions. It's simple and a great way to understand how sorting works!
Middle Node:
Finding the middle node of a linked list was a really fun thing to learn. I used a smart trick with two pointers:
One pointer moves fast (two steps at a time), and the other moves slow (one step at a time).
When the fast pointer reaches the end of the list, the slow pointer is at the middle.
Thanks!
Top comments (0)