Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Comprehensive Ruby Programming

You're reading from   Comprehensive Ruby Programming From beginner to confident programmer

Arrow left icon
Product type Paperback
Published in Jun 2017
Publisher Packt
ISBN-13 9781787280649
Length 330 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Jordan Hudgens Jordan Hudgens
Author Profile Icon Jordan Hudgens
Jordan Hudgens
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Introduction to the Ruby Programming Language 2. Ruby Variables FREE CHAPTER 3. Ruby Strings 4. Working with Numbers in Ruby 5. Ruby Methods 6. Ruby Iterators and Loops 7. Ruby Collections 8. Ruby Conditionals 9. Object-Oriented Programming in Ruby 10. Working with the Filesystem in Ruby 11. Error Handling in Ruby 12. Regular Expressions in Ruby 13. Searching with grep in Ruby 14. Ruby Gems 15. Ruby Metaprogramming 16. Ruby Web Frameworks 17. Working with APIs in Ruby 18. Ruby Algorithms 19. Machine Learning

Introduction to sorting algorithms

Welcome to the algorithm section of this course. The next few sections will surely be interesting as we are going to talk about some advanced topics in computer science. These algorithms will help you understand how programming works and give you the tools you'll need to build your own advanced programs.

We'll start out with the sorting algorithms. The reason why we're starting with sorting is because it supplies some of the foundational knowledge that you'll be able to use in more advanced topics, as you'll see as you work through the section.

To explore sorting, let's start by creating an array:

a = [1, 5, 1, 2, 10, 100, 3, 1] 

If you want to sort these values in ascending order, all that you have to do is run:

a.sort  

The output will be [1, 1, 2, 3, 5, 10, 100].

Since this sort method works great, there&apos...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime