From a5eb9cd160aeafad2341263bf06d155a7c110796 Mon Sep 17 00:00:00 2001 From: Jidong Xiao Date: Mon, 11 Sep 2023 00:42:21 -0400 Subject: [PATCH] adding the array sorting section --- lectures/04_pointers/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lectures/04_pointers/README.md b/lectures/04_pointers/README.md index 84ff2a7..bfa1a82 100644 --- a/lectures/04_pointers/README.md +++ b/lectures/04_pointers/README.md @@ -118,7 +118,15 @@ a[i] = sqrt( double(i) ); - Remember: the size of array a is fixed at compile time. STL vectors act like arrays, but they can grow and shrink dynamically in response to the demands of the application. -## 4.7 Exercises +## 4.7 Sorting an Array + +- Arrays may be sorted using std::sort, just like vectors. Pointers are used in place of iterators. For example, if a is an array of doubles and there are n values in the array, then here’s how to sort the values in the array into increasing order: + +```cpp +std::sort( a, a+n ); +``` + +## 4.8 Exercises - [Leetcode problem 905: Sort Array By Parity](https://leetcode.com/problems/sort-array-by-parity/). Solution: [p905_sortarraybyparity.cpp](../../leetcode/p905_sortarraybyparity.cpp) - [Leetcode problem 977: Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array/). Solution: [p977_sortedsquare.cpp](../../leetcode/p977_sortedsquare.cpp)