From the course: C: Data Structures, Pointers, and File Systems

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Sorting data

Sorting data - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

Sorting data

- [Instructor] Sorting is one of those mindless, repetitive tasks that doesn't bother a computer at all. As a programmer, your job is to code the sort. The simplest form of sort is the bubble sort which is easy to understand in code but a lot slower than some of the more effective, efficient methods. This code offers a bubble sort on the list array of 100 random integers. The first chunk of code assigns those 100 random values to the ArrayList. Then it displays the values. The bubble sort starts at line 25. It uses a nested loop to compare each array element to every other array element. The outer for loop with the variable a traverses from element zero in the array list to the next to last element which is size minus one. The inner for loop at line 27 with variable b moves from one plus the value of variable a up to the full size of the array. Now line 30 compares both values. To sort from smallest to largest, if the value of the first variable is greater than the value of the…

Contents