100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4.2 TrustPilot
logo-home
Samenvatting

Summary Ch02_Bag_Implementations_That_Use_Arrays

Beoordeling
-
Verkocht
-
Pagina's
38
Geüpload op
26-06-2021
Geschreven in
2019/2020

Ch02_Bag_Implementations_That_Use_Arrays

Instelling
Vak











Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Gekoppeld boek

Geschreven voor

Instelling
Vak

Documentinformatie

Heel boek samengevat?
Ja
Geüpload op
26 juni 2021
Aantal pagina's
38
Geschreven in
2019/2020
Type
Samenvatting

Onderwerpen

Voorbeeld van de inhoud

Data Structures and Abstractions with Java ™
5th Edition

Chapter 2


Bag
Implementations
That Use Arrays

Copyright © 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved

,Fixed-Size Array to Implement the ADT Bag




FIGURE 2-1 A classroom that contains desks in fixed positions
Copyright © 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved

, UML for a fixed size ArrayBag
ArrayBag
-bag: T[]
-numberOfEntries: integer
-DEFAULT_CAPACITY: integer
+getCurrentSize(): integer
+isEmpty(): boolean
+add(newEntry: T): boolean
+remove(): T
+remove(anEntry: T): boolean
+clear(): void
+getFrequencyOf(anEntry: T):
integer
+contains(anEntry: T): boolean
+toArray(): T[]
–isArrayFull(): boolean


FIGURE 2-2 UML notation for the class ArrayBag, including the class’s data fields
Copyright © 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved

, The Class ArrayBag (Part 1)
/**A class of bags whose entries are stored in a fixed-size array.
INITIAL, INCOMPLETE DEFINITION; no security checks */
public final class ArrayBag<T> implements BagInterface<T>
{
private final T[] bag;
private int numberOfEntries;
private static final int DEFAULT_CAPACITY = 25;

/** Creates an empty bag whose initial capacity is 25. */
public ArrayBag()
{
this(DEFAULT_CAPACITY);
} // end default constructor

/** Creates an empty bag having a given initial capacity.
@param desiredCapacity The integer capacity desired. */
public ArrayBag(int desiredCapacity)
{
// The cast is safe because the new array contains null entries.
@SuppressWarnings("unchecked")
T[] tempBag = (T[])new Object[desiredCapacity]; // Unchecked cast
bag = tempBag;
numberOfEntries = 0;
} // end constructor

LISTING 2-1 An outline of the class ArrayBag
Copyright © 2019, 2015, 2012 Pearson Education, Inc. All Rights Reserved
€4,81
Krijg toegang tot het volledige document:

100% tevredenheidsgarantie
Direct beschikbaar na je betaling
Lees online óf als PDF
Geen vaste maandelijkse kosten

Maak kennis met de verkoper
Seller avatar
SomaSan

Maak kennis met de verkoper

Seller avatar
SomaSan IUG
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
0
Lid sinds
4 jaar
Aantal volgers
0
Documenten
4
Laatst verkocht
-

0,0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen