Array Data Structure – Practice Questions
Question 1:
Write a program to sort an array consisting only of 0s, 1s, and 2s.
Input: An array of size N containing only 0, 1, and 2.
Output: The sorted array.
Example:
Input: [0, 2, 1, 2, 0]
Output: [0, 0, 1, 2, 2]
Question 2:
Write a program to insert an element into an array at a given position.
Input: An array, the element to be inserted, and the position.
Output: Array after inserting the element.
Example:
Array: [10, 20, 30, 40]
Element: 25, Position: 3
Output: [10, 20, 25, 30, 40]