From the course: Master C Language Pointers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Sorting pointers - C Tutorial
From the course: Master C Language Pointers
Sorting pointers
- [Instructor] Sorting pointers in C helps organize data without requiring the data to be moved. So this code shows the old way to sort. You see a standard two-dimensional array, weekdays, here. A simple bubble sort starts at line 20. Lots of activity takes place in lines 27, 28, and 29. All this copying of data is required to organize the array to put it in alphabetical order. The result is then output with another for loop here at line 36. Build and run. And you see the weekdays in their regular presentation and sorted. This code works but the overhead required to copy the string data here is immense. For a small array like this, the computer can handle it but for large quantities of data, it's a bottleneck. This version of the code sorts pointers. The days of the week are declared as a pointer array. These are memory locations. The strings, well, they sit off in memory somewhere and they stay there. They don't need…
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)
Understanding pointers to pointers4m 32s
-
(Locked)
Sending a pointer to a function3m 36s
-
(Locked)
Sorting pointers2m 6s
-
(Locked)
Managing memory3m 56s
-
(Locked)
Creating pointers to functions2m 30s
-
(Locked)
Challenge: Manipulate a pointer array1m 18s
-
(Locked)
Solution: Manipulate a pointer array3m 20s
-
(Locked)