1. The function add(int location, int item) is not a valid operation of bags. ad
ID: 3798507 • Letter: 1
Question
1. The function add(int location, int item)
is not a valid operation of bags.
adds the item at the end of the bag.
replaces the item in the bag at the position specified by location.
adds the item to the bag at the position specified by location.
public void operation(int item)
{
if (numberOfItems == SIZE) System.out.println("ERROR");
else
{
listArray[numberOfItems] = item;
numberOfItems++;
}
} clear
remove
add
display
Explanation / Answer
public void operation(int item)
{
// if total number of items in listArray is equal to size, print error
if (numberOfItems == SIZE) System.out.println("ERROR");
// else put the item at the end of the listArray and increment count of
// the total number of itms in listArray
else
{
listArray[numberOfItems] = item;
numberOfItems++;
}
}
Given function does the add operation to the listArray
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.