Difficulty Range: Freshmen
This is a simple, easy way to make your own subarray system. It is important to understand these to get a grasp on how they work and it’s a fun simple problem. Create an array from another array from one position to the end position you select. This smaller array will have all the elements in that range.
Input: 1,5,78,13,8,23,8,73,75,138,2 Subarray(arr,3,7)
Output: 78,13,8,23
Solution :
This is a generic solution, but if you don’t understand just substitute T for any datatype you prefer.
T Subarray<T>[](T[] array,int start,int end){
T[] sub = new T[];
Int x =0;
for(int i = start;i < end;i ++ ){
Sub[x] = array[start];
x++;
}
Return sub;
}