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 - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Solving math puzzles3m 32s
-
(Locked)
Creating random numbers3m 42s
-
(Locked)
Working with time functions3m 54s
-
(Locked)
Sorting data4m 8s
-
(Locked)
Debugging your code2m
-
(Locked)
Using a debugger4m 53s
-
(Locked)
Writing your own header file2m 53s
-
(Locked)
Mixing multiple source code files4m
-
(Locked)
Challenge: Lotto simulation1m 18s
-
(Locked)
Solution: Lotto simulation2m 29s
-
(Locked)
-