Determine if the following statements is true or false. Screen shot shows the text's arraycollection and sortedarraycollection With the text's array-based collection implementation, the set of stored elements is scattered about the array. The text's sorted array-based collection implementation stores elements in the lowest possible indices of the array.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 17PE
icon
Related questions
Question
100%

Determine if the following statements is true or false.

Screen shot shows the text's arraycollection and sortedarraycollection

With the text's array-based collection implementation, the set of stored elements is scattered about the array.

The text's sorted array-based collection implementation stores elements in the lowest possible indices of the array.

When comparing two objects using the equals method inherited from the Object class, what is actually compared is the contents of the objects.

 
 
 
l/page 1
/page 2
public class SertedARACAllestion T> implements Colactionloterface T>{
protected final iptDEFCAP = 100; / default capacity
protected ipt oviCaR: // original capacity
protected TH elements; // array to hold collection elements
protected ipt AplApogtsF 0; // number of elements in this collection
public beolagn addCT element)
I/ Precondition: element is Comparable to previously added objects
//
// Adds element to this collection.
// set by find method
protected beplgUA found; // true if target found, otherwise false
protected int location; // indicates location of target
enlarge):
found,
find(element); // sets location to index where element belongs
for (int index =nypElenentsy index > location; index-)
elements[index] =elepeotskindex - 1];
public SartodArayCallestion) {
elements = (TH) new Object[DEFCAP];
rieCUA = DEFCAP:
}
elements[location] = element;
public SertodArayCAllestionkiok.capacity) {
elements = (TH) new Objectſcapacity);
this OKIAG= capacity;
return true;
public beolaga epove(T target)
I/ Removes an element e from this collection such that eeguals(target)
}
protected void enlargeo
// Increments the capacity of the collection by an amount
I/ equal to the original capacity.
// and returns true; if no such element exists, returns false.
find(target);
if (found) {
// Create the larger array.
TN larger = (TI) new Objectſekppots-laogt origCarl;
for (ipki= location; i=guDAleeAs - 2; itt)
elements[i = eleeotski+ 1];
elemeptskuAEleERIS - 1]= null;
// Copy the contents from the smaller array into the larger array.
for (ipki=0; i< nAELveRs: t) {
larger[ = elements[1;
return found:
}
// Reassign elements reference.
elements = larger;
public ipt size)
// Retums the number of elements on this collection.
}
{
return nOlooCNA:
protected void tjadCT target)
// Searches elements for an occurrence of an element e such that
/leRAValstarget). If successful, sets instance variables
// found to true and location to the array index of e. If
// not successful, sets found to false and location to the
I/ array index where target should be inserted.
}
public baolagn ceptainsT target)
// Retums true if this collection contains an element e such that
//eRAVlstarget); otherwise, returns false.
find(target);
return found;
location = 0;
found = false;
if CisERORA)
}
public T getT target)
/ Retums an element e from this collection such that eAguals(target);
// if no such element exists, returns null.
ckindktarget, 0, nADElaments - 1);
protected void reckindT target, ipt first, ipt last)
/ Used by find.
find(target);
if (found)
ipt result; // result of the comparison
if (first> last) {
returm elements[location];
else
found = false;
result = ((Comparable) target.ceppa(elements[location]);
return null;
}
if (result > 0)
public beoloun ISERORAN
// Retums true if this collection is empty; otherwise, returns false.
location++; // adjust location to indicate insert index
} else {
location = (first + last) / 2;
result = ((Comparable) target)ceppeRTe(elements[location]);
if (result= 0) // found target
return (OABlooents=0);
found = true:
else if (result > 0) // target too high
public beolowa isENUO
reckindtarget, location + 1, last);
I/ This collection is unbounded so always returns false.
{
else // target too low
ckinktarget, first, location - 1):
return false:
}
Transcribed Image Text:l/page 1 /page 2 public class SertedARACAllestion T> implements Colactionloterface T>{ protected final iptDEFCAP = 100; / default capacity protected ipt oviCaR: // original capacity protected TH elements; // array to hold collection elements protected ipt AplApogtsF 0; // number of elements in this collection public beolagn addCT element) I/ Precondition: element is Comparable to previously added objects // // Adds element to this collection. // set by find method protected beplgUA found; // true if target found, otherwise false protected int location; // indicates location of target enlarge): found, find(element); // sets location to index where element belongs for (int index =nypElenentsy index > location; index-) elements[index] =elepeotskindex - 1]; public SartodArayCallestion) { elements = (TH) new Object[DEFCAP]; rieCUA = DEFCAP: } elements[location] = element; public SertodArayCAllestionkiok.capacity) { elements = (TH) new Objectſcapacity); this OKIAG= capacity; return true; public beolaga epove(T target) I/ Removes an element e from this collection such that eeguals(target) } protected void enlargeo // Increments the capacity of the collection by an amount I/ equal to the original capacity. // and returns true; if no such element exists, returns false. find(target); if (found) { // Create the larger array. TN larger = (TI) new Objectſekppots-laogt origCarl; for (ipki= location; i=guDAleeAs - 2; itt) elements[i = eleeotski+ 1]; elemeptskuAEleERIS - 1]= null; // Copy the contents from the smaller array into the larger array. for (ipki=0; i< nAELveRs: t) { larger[ = elements[1; return found: } // Reassign elements reference. elements = larger; public ipt size) // Retums the number of elements on this collection. } { return nOlooCNA: protected void tjadCT target) // Searches elements for an occurrence of an element e such that /leRAValstarget). If successful, sets instance variables // found to true and location to the array index of e. If // not successful, sets found to false and location to the I/ array index where target should be inserted. } public baolagn ceptainsT target) // Retums true if this collection contains an element e such that //eRAVlstarget); otherwise, returns false. find(target); return found; location = 0; found = false; if CisERORA) } public T getT target) / Retums an element e from this collection such that eAguals(target); // if no such element exists, returns null. ckindktarget, 0, nADElaments - 1); protected void reckindT target, ipt first, ipt last) / Used by find. find(target); if (found) ipt result; // result of the comparison if (first> last) { returm elements[location]; else found = false; result = ((Comparable) target.ceppa(elements[location]); return null; } if (result > 0) public beoloun ISERORAN // Retums true if this collection is empty; otherwise, returns false. location++; // adjust location to indicate insert index } else { location = (first + last) / 2; result = ((Comparable) target)ceppeRTe(elements[location]); if (result= 0) // found target return (OABlooents=0); found = true: else if (result > 0) // target too high public beolowa isENUO reckindtarget, location + 1, last); I/ This collection is unbounded so always returns false. { else // target too low ckinktarget, first, location - 1): return false: }
//Page 1
fage 2
public class Araxsallestion<T> implements ÇRleetİRARtefaca<T>
return found;
protected final iptDEFCAP = 100; // default capacity
protected TH elements;
protected intauklervents = l / number of elements in this collection
}
// array to hold calectians elements
public beaRAA contains (T target)
// Returns true if this collection contains an element e such that
// eeuNstarget); otherwise, returns false.
// set by find method
protected beglRA, foundil true if target found, otherwise false
protected intJocation:of/ indicates location of target if found
{
find(target);
return found;
public ArraxGoUestiool
{
elements = (TH) new Object[DEFCAP);
}
public T getT target)
// Returns an element e from this collection such that eeAuals(target);
// if no such element exists, returns null.
}
public ArraxSolestiooliotcapacity)
{
find(target);
if (found)
return elements(location];
{
elements = (TH) new Object[capacity];
else
protected void find(T target)
// Searches elements for an occurrence of an element e such that
// eeAHals(target). If successful, sets instance variables
// found to true and location to the array index of e. If
// not successful, sets found to false.
return null;
}
public baalRAniSkW
// Returns true if this collection is full; otherwise, returns false.
ipJocation = 0;
return (Qulerverts== elevevslkreth):
}
found = false;
while (location < nuklervente)
public bealRAniskRR
// Returns true if this collection is empty; otherwise, returns false.
{
if (elements[locationleayals(target))
{
found = true;
return (QuAeoerts == 0);
}
return;
public intsize)
// Returns the number of elements in this collection.
}
else
location++;
{
return QuElerperts
}
public baaRAnaddIT element)
// Attempts to add element to this collection.
// Returns true if successful, false otherwise.
{
if (işkuU)
return false;
else
elements(uElevects) = element;
return true;
public baaleanremove (T target)
// Removes an element e from this collection such that eeguals(target)
// and returns true; if no such element exists, returns false.
{
find(target);
if (found)
{
elements[location] = elementslRumalevents- 1);
elemertsiounElevects - 1) = null;
Transcribed Image Text://Page 1 fage 2 public class Araxsallestion<T> implements ÇRleetİRARtefaca<T> return found; protected final iptDEFCAP = 100; // default capacity protected TH elements; protected intauklervents = l / number of elements in this collection } // array to hold calectians elements public beaRAA contains (T target) // Returns true if this collection contains an element e such that // eeuNstarget); otherwise, returns false. // set by find method protected beglRA, foundil true if target found, otherwise false protected intJocation:of/ indicates location of target if found { find(target); return found; public ArraxGoUestiool { elements = (TH) new Object[DEFCAP); } public T getT target) // Returns an element e from this collection such that eeAuals(target); // if no such element exists, returns null. } public ArraxSolestiooliotcapacity) { find(target); if (found) return elements(location]; { elements = (TH) new Object[capacity]; else protected void find(T target) // Searches elements for an occurrence of an element e such that // eeAHals(target). If successful, sets instance variables // found to true and location to the array index of e. If // not successful, sets found to false. return null; } public baalRAniSkW // Returns true if this collection is full; otherwise, returns false. ipJocation = 0; return (Qulerverts== elevevslkreth): } found = false; while (location < nuklervente) public bealRAniskRR // Returns true if this collection is empty; otherwise, returns false. { if (elements[locationleayals(target)) { found = true; return (QuAeoerts == 0); } return; public intsize) // Returns the number of elements in this collection. } else location++; { return QuElerperts } public baaRAnaddIT element) // Attempts to add element to this collection. // Returns true if successful, false otherwise. { if (işkuU) return false; else elements(uElevects) = element; return true; public baaleanremove (T target) // Removes an element e from this collection such that eeguals(target) // and returns true; if no such element exists, returns false. { find(target); if (found) { elements[location] = elementslRumalevents- 1); elemertsiounElevects - 1) = null;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning