From the course: Advanced C Programming: Optimize Performance and Efficiency
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Sort an array - C Tutorial
From the course: Advanced C Programming: Optimize Performance and Efficiency
Sort an array
- [Instructor] The computer can plow through a tediously long array of numbers and place them in order. It does so without complaint and it creates the sorted list as fast as your program allows. To meet your sorting needs in the C language, you have several options. The most basic sort is the bubble sort. It's not very efficient, but it's easy to understand. Open exercise file 04-01_arraysort1. This is a rather long piece of source code but it's divided up into chunks. Starting at line 12, the array is initialized. The number of elements is set by the size constant which is defined at line 5. At line 15, the array is filled with random values. The expression at line 15 ensures that the random values lie in the range between 1 and 100. Lines 18 through 21 display each number in the array. You see the %3d placeholder used in the printf function at line 20. That allows a character width of three digits for each number,…
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)
Sort an array6m 39s
-
(Locked)
Challenge: Sort a string24s
-
(Locked)
Solution: Sort a string1m 28s
-
(Locked)
Work with arrays and functions3m 21s
-
(Locked)
Challenge: An array-modification function24s
-
(Locked)
Solution: An array-modification function1m 16s
-
(Locked)
Send a structure to a function4m
-
(Locked)
Challenge: Create a structure function27s
-
(Locked)
Solution: Create a structure function1m 20s
-
(Locked)
Build an array of structures3m 36s
-
(Locked)
Challenge: Sort an array of structures32s
-
(Locked)
Solution: Sort an array of structures1m 7s
-
(Locked)
-
-