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

Sorting pointers - C Tutorial

From the course: Master C Language Pointers

Start my 1-month free trial

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…

Contents