Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Statement: Take an integer as input that indicates the size of a dynamically allocated integer array ( one dimensional ( ID ) ) .

Problem Statement:
Take an integer as input that indicates the size of a dynamically allocated integer array (one
dimensional (ID)). The array contains positive integers (>0) and -1. Take all the elements of the
array as input. You have to split the elements of the array based on -1. Keep the splitted elements
as the rows of a dynamically allocated two-dimensional (2D) array and print the elements of the
2D array. Finally sort each row of the 2D array and print the elements of the 2D array again.
Procedure: [The rightmost values inside third lhracket indicate marks for implementing functions)
For solving the problem, you have to implement the functions prototyped below:
int" two_dimensional(int "ara, int n, int "total_rows, int "sizes_of_each_row)[10]
ara: ID integer array that contains positive integers (>0) and -1
n : the size of the ara
total_rows: the reference to the number of rows of the newly generated 2D array
sizes_of_each_row: integer array (1D) that stores the sizes of the 1D arrays
indicating the rows of the generated 2D array
This function will return the generated 2D array.
void Printing2D(int *"ara2d, int "sizes_of_each_row, int rows)
ara2d: 2D integer array
sizes_of_each_row: integer array (1D) that stores the sizes of the 1D arrays
indicating the rows of ara2d
rows: The number of rows of ara2d
This function is for printing the contents of ara2d
void sorting2D(int "*ara2d, int "sizes_of_each_row, int rows)
ara2d: 2D integer array
sizes_of_each_row: integer array (ID) that stores the sizes of the ID arrays
indicating the rows of ara 2d
rows: The number of rows of ara2d
This function will sort each row elements of ara 2d separately
Restrictions:
To access an element or to define array size, you can't use array indexing/defining with []
operator. In other words, your code mustn't contain any third bracket [].
You have to use dynamic memory allocation for each array you use and free them when
they are no longer needed. While allocating memory, be careful to efficiently allocate the
memory.
Please first calculate the amount of memory required and then allocate just the needed
amount. Allocation of a constant big amount of memory will result in a penalty.
You are not allowed to change the function prototypes.
-1 cannot be the 1 st or last element of the input 1D array. Also -1 cannot occur side by
side inside the input 1D array.
Sample Inputs/Outputs:
Explanation:
Consider the second test case.
The first line denotes the size of the 1D array and the second line indicates all the elements of the
array. There is only one -1 in the array that splits the 1D array into a 2D array with 2 rows (i.e.,
row No.0=>{32,45,12} and row No.1=>{22,12,78,49,33}. After sorting each row
separately, the rows will be {12,32,45} and {12,22,33,49,78}.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

Use lattice multiplication to determine the product. 6 425

Answered: 1 week ago