Question: ask 3 : Add a new Post / / Adds a new post in the posts array of pointers. / / This function takes as

ask 3: Add a new Post
// Adds a new post in the posts array of pointers. // This function takes as input: //1) the posts array //2) the post id //3) the content of the post //4) the posts array size // And works as follows: //1) If the post exists (there is a post with the post_id), return false. //2) Otherwise: // a) if there is empty space: // i) Insert the post (in the next empty cell)// ii) return true. // b) Else: // i) Double the array size (e.g., if the array has size 16, then increase it to size 32) and then add the post // ii) return true. bool add_post(Post **&posts_array, const unsigned int pid, const char content[MAX_CHAR_NUM], unsigned int &posts_array_size){// TODO: Write code to implement add_post return false; }
For example, here are some examples of post insertion steps:
Example 1: The posts_array is empty and contains two entries
Example 2: Add new post
Example 3: Add new post
Example 4: Increase the size of post array and Add new post

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!