Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java 1. prepend5() -- Given an array of ints, return a new array with the number 5 prepended at the start of the array.

In java

1. prepend5() -- Given an array of ints, return a new array with the number 5 prepended at the start of the array.

prepend5([1, 2, 3]) [5, 1, 2, 3] prepend5([10]) [5, 10] prepend5([20, 42, 1, 6, 5]) [5, 20, 42, 1, 6, 5]

2. deleteFirst() -- Given an array of ints, delete the first element. Return the new array. The new array should be shorter than the given array. You may assume the given array contains at least one element.

deleteFirst([1, 2, 3]) [2, 3] deleteFirst([5, 4, 3, 2, 1]) [4, 3, 2, 1] deleteFirst([10]) []

3. deleteAt() -- Given an array of ints and an index, delete the element at the index. Shift the remaining elements down to fill the gap. Return a new array that is shorter than the given one. You may assume the index is valid.

deleteAt([1, 2, 3], 0) [2, 3] deleteAt([4, 5, 6], 1) [4, 6] deleteAt([9, 8, 7, 6, 5, 4], 4) [9, 8, 7, 6, 4]

4.indexOf() -- Given an array of ints and a target value, return the index of the target. If the target does not appear in the array, return -1. If the target appears multiple times, return the lowest index.

indexOf([1, 2, 3], 3) 2 indexOf([45, 10, 7, 10], 10) 1 indexOf([7, 6, 4, 5], 20) -1

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_2

Step: 3

blur-text-image_3

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 For Advanced Applications 27th International Conference Dasfaa 2022 Virtual Event April 11 14 2022 Proceedings Part 2 Lncs 13246

Authors: Arnab Bhattacharya ,Janice Lee Mong Li ,Divyakant Agrawal ,P. Krishna Reddy ,Mukesh Mohania ,Anirban Mondal ,Vikram Goyal ,Rage Uday Kiran

1st Edition

3031001257, 978-3031001253

More Books

Students also viewed these Databases questions