From the course: C Standard Library
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Sort and search
- [Instructor] Let me briefly tell you about two functions that implement array sort and search respectively. But just to be clear, let me tell you what I mean by sort and search. First, a sort algorithm takes an array where the elements are placed in no particular order and it somehow moves these elements to end up with a sorted array either in ascending or descending order. Now, a search algorithm looks for an element which may or may not be in the array. It compares this element to the elements in the array somehow traversing the array until the element is found or until it learns that the element was not in the array. The sorting function is called qsort and its parameters are the address of the first element in the array, the element count and the size in bytes of each element. The last parameter is a call back function that is used to compare two values as this is the heart of a sorting algorithm. This is a call back function because qsort is supposed to work on any type of…
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
-
-
-
-
-
Memory allocation1m 32s
-
(Locked)
Memory allocation example2m 29s
-
(Locked)
Random number generation1m 48s
-
(Locked)
Random number generation example2m 40s
-
(Locked)
String conversion2m 11s
-
(Locked)
String conversion example6m 29s
-
(Locked)
Sort and search1m 52s
-
(Locked)
Sort and search main4m 50s
-
(Locked)
Sort and search functions5m 6s
-
(Locked)
Challenge: Let's get random1m 38s
-
(Locked)
Solution: Let's get random5m 40s
-
-
-
-