Linked Bag

  • Please change only files: LinkedBag340.cpp and Include.h, no other files.
  • We are to implement 8 small additional functions and 2 helper functions to the Linked Bag.
  • Our programs must produce identical output to the output in the 2 sample runs: Asmt03_Run1.txt and Asmt03_Run2.txt
  • Our Test 9's output must also be identical to the sample output excepts the random values.
  • Our Test 9's random values in our 2 sample runs output must be different.

Descriptions of the 8 functions:

Please ask questions, if any, during the in-class discussions and demos for this assignment.

  • removeSecondNode340 deletes the second node in the Linked Bag.
  • addEnd340 inserts the new node at the end of the Linked Bag.
  • getCurrentSize340Iterative counts the number of nodes in the Linked Bag iteratively.
  • getCurrentSize340Recursive counts the number of nodes in the Linked Bag recursively. Use 1 helper function:
    • getCurrentSize340RecursiveHelper
  • IMMEDIATE RECURSION: getCurrentSize340RecursiveNoHelper counts the number of nodes in the Linked Bag recursively. This recursive function does not use any helper functions.
  • getFrequencyOf340Recursive recursively counts the number of times an entry appears in the Linked Bag. Use 1 helper function: getFrequencyOf340RecursiveHelper.
  • IMMEDIATE RECURSION: getFrequencyOf340RecursiveNoHelper recursively counts the number of times an entry appears in the Linked Bag. This recursive function does not use any helper functions.
  • removeRandom340 removes a random entry from the Linked Bag.

Linked Bag, Smart Pointers Version.

Create a Smart Pointers version of your PART B's Linked Bag:

  • Please create a copy of your entire PART B solution and name it: PartC_SmartPointers.
  • Then go through all the files, not just LinkedBag340.cpp, and use smart pointers properly where it is possible.
  • In your assignment report, list the file names and the line numbers in which you use smart pointers. For each smart pointer, explain in 3 or more sentences why it is a proper use.
  • This Smart Pointers version must work properly and produce identical output like that of your PART B version.
  • Please add a destructor so that the program displays when object(s) get destroyed.

Starter Code

BagInterface.h

// BagInterface.h
// Created by Frank M. Carrano and Timothy M. Henry.
// Updated by Duc Ta
// Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

#pragma once
#include < vector>

//
//
// PLEASE DO NOT CHANGE THIS FILE
//
//

template< typename ItemType>
class BagInterface {
public:
/*--------------------------CSC340------------------------------*/
// Remove the second node
virtual bool removeSecondNode340() = 0;

// Add a node to the end of the linked list
virtual bool addEnd340(const ItemType&) = 0;

// getCurrentSize() - Iterative
virtual int getCurrentSize340Iterative() const = 0;

// getCurrentSize() - Recursive
virtual int getCurrentSize340Recursive() const = 0;

// getCurrentSize() - Recursive
virtual int getCurrentSize340RecursiveNoHelper() const = 0;

// getFrequencyOf340Recursive() - Recursive
virtual int getFrequencyOf340Recursive(const ItemType&) const = 0;

// getFrequencyOf340Recursive() - Recursive
virtual int getFrequencyOf340RecursiveNoHelper(const ItemType&) const = 0;

// Remove a random node
virtual ItemType removeRandom340() = 0;
/*--------------------------------------------------------------*/

// Gets the current number of entries in this bag.
virtual int getCurrentSize() const = 0;

// Sees whether this bag is empty.
virtual bool isEmpty() const = 0;

// Adds a new entry to this bag.
virtual bool add(const ItemType&) = 0;

// Removes one occurrence of a given entry from this bag, if possible.
virtual bool remove(const ItemType&) = 0;

// Removes all entries from this bag.
virtual void clear() = 0;

// Counts the number of times a given entry appears in bag.
virtual int getFrequencyOf(const ItemType&) const = 0;

// Tests whether this bag contains a given entry.
virtual bool contains(const ItemType&) const = 0;

// Empties and then fills a given vector with all entries that are in this bag.
virtual std::vector< ItemType> toVector() const = 0;

// Destroys object and frees memory allocated by object.
virtual ~BagInterface() { }
}; // end BagInterface

LinkedBag.cpp

// LinkedBag.cpp
// Created by Frank M. Carrano and Timothy M. Henry.
// Updated by Duc Ta
// Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

#include < cstddef>
#include "Node.h"
#include "LinkedBag.h"

//
//
// PLEASE DO NOT CHANGE THIS FILE
//
//

template< typename ItemType>
LinkedBag< ItemType>::LinkedBag() : headPtr(nullptr), itemCount(0) {}

template< typename ItemType>
LinkedBag< ItemType>::LinkedBag(const LinkedBag< ItemType>& aBag) {
itemCount = aBag.itemCount;
Node< ItemType>* origChainPtr = aBag.headPtr;

if (origChainPtr == nullptr) {
headPtr = nullptr;
}
else {
headPtr = new Node< ItemType>();
headPtr->setItem(origChainPtr->getItem());

Node< ItemType>* newChainPtr = headPtr;
origChainPtr = origChainPtr->getNext();

while (origChainPtr != nullptr)
{
ItemType nextItem = origChainPtr->getItem();
Node< ItemType>* newNodePtr = new Node< ItemType>(nextItem);
newChainPtr->setNext(newNodePtr);
newChainPtr = newChainPtr->getNext();
origChainPtr = origChainPtr->getNext();
}

newChainPtr->setNext(nullptr);
}
}

template< typename ItemType>
LinkedBag< ItemType>::~LinkedBag() {
clear();
}

template< typename ItemType>
bool LinkedBag< ItemType>::isEmpty() const {
return itemCount == 0;
}

template< typename ItemType>
int LinkedBag< ItemType>::getCurrentSize() const {
return itemCount;
}

template< typename ItemType>
bool LinkedBag< ItemType>::add(const ItemType& newEntry) {
Node< ItemType>* nextNodePtr = new Node< ItemType>();
nextNodePtr->setItem(newEntry);
nextNodePtr->setNext(headPtr);
headPtr = nextNodePtr;
itemCount++;
return true;
}

template< typename ItemType>
std::vector< ItemType> LinkedBag< ItemType>::toVector() const {
std::vector< ItemType> bagContents;
Node< ItemType>* curPtr = headPtr;
int counter = 0;

while ((curPtr != nullptr) && (counter < itemCount)) {
bagContents.push_back(curPtr->getItem());
curPtr = curPtr->getNext();
counter++;
}

return bagContents;
}

template< typename ItemType>
bool LinkedBag< ItemType>::remove(const ItemType& anEntry) {
Node< ItemType>* entryNodePtr = getPointerTo(anEntry);
bool canRemoveItem = !isEmpty() && (entryNodePtr != nullptr);

if (canRemoveItem) {
entryNodePtr->setItem(headPtr->getItem());
Node< ItemType>* nodeToDeletePtr = headPtr;
headPtr = headPtr->getNext();

nodeToDeletePtr->setNext(nullptr);
delete nodeToDeletePtr;
nodeToDeletePtr = nullptr;

itemCount--;
}

return canRemoveItem;
}

template< typename ItemType>
void LinkedBag< ItemType>::clear() {
Node< ItemType>* nodeToDeletePtr = headPtr;

while (headPtr != nullptr) {
headPtr = headPtr->getNext();
nodeToDeletePtr->setNext(nullptr);
delete nodeToDeletePtr;
nodeToDeletePtr = headPtr;
}

itemCount = 0;
}

template< typename ItemType>
int LinkedBag< ItemType>::getFrequencyOf(const ItemType& anEntry) const {
int frequency = 0;
int counter = 0;
Node< ItemType>* curPtr = headPtr;

while ((curPtr != nullptr) && (counter < itemCount)) {
if (anEntry == curPtr->getItem()) {
frequency++;
}
counter++;
curPtr = curPtr->getNext();
}

return frequency;
}

template< typename ItemType>
bool LinkedBag< ItemType>::contains(const ItemType& anEntry) const {
return (getPointerTo(anEntry) != nullptr);
}

template< typename ItemType>
Node< ItemType>* LinkedBag< ItemType>::getPointerTo(const ItemType& anEntry) const {
bool found = false;
Node< ItemType>* curPtr = headPtr;

while (!found && (curPtr != nullptr)) {
if (anEntry == curPtr->getItem()) {
found = true;
}
else {
curPtr = curPtr->getNext();
}
}

return curPtr;
}

LinkedBag.h

// LinkedBag.h
// Created by Frank M. Carrano and Timothy M. Henry.
// Updated by Duc Ta
// Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

#pragma once
#include "Node.cpp"
#include "BagInterface.h"

//
//
// PLEASE DO NOT CHANGE THIS FILE
//
//

template< typename ItemType>
class LinkedBag : public BagInterface< ItemType> {

/*--------------------------CSC340-------------------------------------*/
public:
bool removeSecondNode340();
bool addEnd340(const ItemType&);
int getCurrentSize340Iterative() const;
int getCurrentSize340Recursive() const;
int getCurrentSize340RecursiveNoHelper() const;
int getFrequencyOf340Recursive(const ItemType&) const;
int getFrequencyOf340RecursiveNoHelper(const ItemType&) const;
ItemType removeRandom340();
private:
int getCurrentSize340RecursiveHelper(Node< ItemType>*) const; // if needed
int getFrequencyOf340RecursiveHelper(Node< ItemType>*, const ItemType&) const; // if needed
/*----------------------------------------------------------------------*/

public:
LinkedBag();
LinkedBag(const LinkedBag< ItemType>&);
virtual ~LinkedBag();
int getCurrentSize() const;
bool isEmpty() const;
bool add(const ItemType&);
bool remove(const ItemType&);
void clear();
bool contains(const ItemType&) const;
int getFrequencyOf(const ItemType&) const;
std::vector< ItemType> toVector() const;

private:
Node< ItemType>* headPtr{ nullptr }; // Pointer to first node
int itemCount{ 0 }; // Current count of bag items

// pointer to the node or the null pointer
Node< ItemType>* getPointerTo(const ItemType&) const;
};

LinkedBagClient340.cpp

// LinkedBagClient340.cpp
// Created by: Duc Ta

#include "Include.h"

//
//
// PLEASE DO NOT CHANGE THIS FILE
//
//

void displayBag(const unique_ptr< LinkedBag< string>>&);

int main() {

cout < < "----- LINKED BAG 340 C++-----" < < endl < < endl;

// 1. Create a bag and add initial nodes
cout < < "--->>>>> Test 1 --->>>>>" < < endl;
unique_ptr< LinkedBag< string>> bag { make_unique < LinkedBag< string>>() };

// A small vector of small objects to test the bag
vector< string> items { "#-END", "5-FIVE", "4-FOUR", "4-FOUR", "3-THREE", "2-TWO", "1-ONE", "0-ZERO", "#-BEGIN" };
cout < < " !add()... ";
vector< string>::const_iterator cItr;
for (cItr = items.begin(); cItr != items.end(); cItr++) {
cout < < *cItr < < " ";
bool success = bag->add(*cItr);
if ( !success) {
cout < < " !add() FAILED: " < < *cItr < < endl;
}
}
displayBag(bag);

// 2. Remove the second node
cout < < "\n--->>>>> Test 2 --->>>>>";
cout < < "\n !removeSecondNode340()... ";
bag->removeSecondNode340();
cout < < "\n !removeSecondNode340()... ";
bag->removeSecondNode340();
displayBag(bag);
cout < < "\n !removeSecondNode340()... ";
bag->removeSecondNode340();
cout < < "\n !removeSecondNode340()... ";
bag->removeSecondNode340();
displayBag(bag);

// 3. Add a node to the end of the linked list
cout < < "\n--->>>>> Test 3 --->>>>>";
cout < < "\n !addEnd340()... ";
bag->addEnd340("9-NINE");
cout < < "\n !addEnd340()... ";
bag->addEnd340("4-FOUR");
displayBag(bag);
cout < < "\n !addEnd340()... ";
bag->addEnd340("9-NINE");
cout < < "\n !addEnd340()... ";
bag->addEnd340("0-ZERO");
displayBag(bag);

// 4. getCurrentSize() - Iterative
cout < < "\n--->>>>> Test 4 --->>>>>";
cout < < "\n !getCurrentSize340Iterative - Iterative... ";
cout < < "\n ---> Current size: " < < bag->getCurrentSize340Iterative();
displayBag(bag);

// 5. getCurrentSize() - Recursive
cout < < "\n--->>>>> Test 5 --->>>>>";
cout < < "\n !getCurrentSize340Recursive() - Recursive... ";
cout < < "\n ---> Current size: " < < bag->getCurrentSize340Recursive();
displayBag(bag);

// 6. getCurrentSize() - Recursive w/ no helper function
cout < < "\n--->>>>> Test 6 --->>>>>";
cout < < "\n !getCurrentSize340RecursiveNoHelper() - Recursive... ";
cout < < "\n ---> Current size: " < < bag->getCurrentSize340RecursiveNoHelper();
displayBag(bag);

// 7. getFrequencyOf() - Recursive
cout < < "\n--->>>>> Test 7 --->>>>>";

cout < < "\n !getFrequencyOf()... ";
cout < < "\n ---> 0-ZERO: " < < bag->getFrequencyOf("0-ZERO");
cout < < "\n ---> 1-ONE: " < < bag->getFrequencyOf("1-ONE");
cout < < "\n ---> 2-TWO: " < < bag->getFrequencyOf("2-TWO");
cout < < "\n ---> 4-FOUR: " < < bag->getFrequencyOf("4-FOUR");
cout < < "\n ---> 9-NINE: " < < bag->getFrequencyOf("9-NINE");
displayBag(bag);

cout < < "\n !getFrequencyOf340Recursive() - Recursive... ";
cout < < "\n ---> 0-ZERO: " < < bag->getFrequencyOf340Recursive("0-ZERO");
cout < < "\n ---> 1-ONE: " < < bag->getFrequencyOf340Recursive("1-ONE");
cout < < "\n ---> 2-TWO: " < < bag->getFrequencyOf340Recursive("2-TWO");
cout < < "\n ---> 4-FOUR: " < < bag->getFrequencyOf340Recursive("4-FOUR");
cout < < "\n ---> 9-NINE: " < < bag->getFrequencyOf340Recursive("9-NINE");
displayBag(bag);

// 8. getFrequencyOf() - Recursive w/ no helper fuction
cout < < "\n--->>>>> Test 8 --->>>>>";
cout < < "\n !getFrequencyOf340RecursiveNoHelper() - Recursive... ";
cout < < "\n ---> 0-ZERO: " < < bag->getFrequencyOf340RecursiveNoHelper("0-ZERO");
cout < < "\n ---> 1-ONE: " < < bag->getFrequencyOf340RecursiveNoHelper("1-ONE");
cout < < "\n ---> 2-TWO: " < < bag->getFrequencyOf340RecursiveNoHelper("2-TWO");
cout < < "\n ---> 4-FOUR: " < < bag->getFrequencyOf340RecursiveNoHelper("4-FOUR");
cout < < "\n ---> 9-NINE: " < < bag->getFrequencyOf340RecursiveNoHelper("9-NINE");
displayBag(bag);

// 9. Remove a random node
cout < < "\n--->>>>> Test 9 --->>>>>";
cout < < "\n !removeRandom340() ---> " < < bag->removeRandom340();
cout < < "\n !removeRandom340() ---> " < < bag->removeRandom340();
displayBag(bag);
cout < < "\n !removeRandom340() ---> " < < bag->removeRandom340();
cout < < "\n !removeRandom340() ---> " < < bag->removeRandom340();
displayBag(bag);
cout < < "\n !removeRandom340() ---> " < < bag->removeRandom340();
cout < < "\n !removeRandom340() ---> " < < bag->removeRandom340();
displayBag(bag);
cout < < "\n !removeRandom340() ---> " < < bag->removeRandom340();
cout < < "\n !removeRandom340() ---> " < < bag->removeRandom340();
displayBag(bag);

cout < < endl;
return 0;
}

// Display the current contents in the bag
void displayBag(const unique_ptr< LinkedBag< string>>& bag) {
cout < < "\n !Display bag: ";
auto bagItems = make_unique< vector< string>>(bag->toVector());

vector< string>::const_iterator cItr;
for (cItr = bagItems->begin(); cItr != bagItems->end(); cItr++) {
cout < < *cItr < < " ";
}

cout < < "\n -----------> " < < bagItems->size() < < " item(s) total";
cout < < endl;
}

Node.cpp

// Node.cpp
// Created by Frank M. Carrano and Timothy M. Henry.
// Updated by Duc Ta
// Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

#include "Node.h"

//
//
// PLEASE DO NOT CHANGE THIS FILE
//
//

template< typename ItemType>
Node< ItemType>::Node() : item(), next(nullptr) {}

template< typename ItemType>
Node< ItemType>::Node(const ItemType& anItem) : item(anItem), next(nullptr) {}

template< typename ItemType>
Node< ItemType>::Node(const ItemType& anItem, Node< ItemType>* nextNodePtr) :
item(anItem), next(nextNodePtr) {}

template< typename ItemType>
void Node< ItemType>::setItem(const ItemType& anItem) {
item = anItem;
}

template< typename ItemType>
void Node< ItemType>::setNext(Node< ItemType>* nextNodePtr) {
next = nextNodePtr;
}

template< typename ItemType>
ItemType Node< ItemType>::getItem() const {
return item;
}

template< typename ItemType>
Node< ItemType>* Node< ItemType>::getNext() const {
return next;
}

Node.h

// Node.h
// Created by Frank M. Carrano and Timothy M. Henry.
// Updated by Duc Ta
// Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

#pragma once

//
//
// PLEASE DO NOT CHANGE THIS FILE
//
//

template< typename ItemType>
class Node {
public:
Node();
Node(const ItemType&);
Node(const ItemType&, Node< ItemType>*);
void setItem(const ItemType&);
void setNext(Node< ItemType>*);
ItemType getItem() const;
Node< ItemType>* getNext() const;

private:
ItemType item{}; // A data item
Node< ItemType>* next{ nullptr }; // Pointer to next node
};

Asmt04_Run1.txt

----- LINKED BAG 340 C++-----

--->>>>> Test 1 --->>>>>
!add()... #-END 5-FIVE 4-FOUR 4-FOUR 3-THREE 2-TWO 1-ONE 0-ZERO #-BEGIN
!Display bag: #-BEGIN 0-ZERO 1-ONE 2-TWO 3-THREE 4-FOUR 4-FOUR 5-FIVE #-END
-----------> 9 item(s) total

--->>>>> Test 2 --->>>>>
!removeSecondNode340()...
!removeSecondNode340()...
!Display bag: #-BEGIN 2-TWO 3-THREE 4-FOUR 4-FOUR 5-FIVE #-END
-----------> 7 item(s) total

!removeSecondNode340()...
!removeSecondNode340()...
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END
-----------> 5 item(s) total

--->>>>> Test 3 --->>>>>
!addEnd340()...
!addEnd340()...
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR
-----------> 7 item(s) total

!addEnd340()...
!addEnd340()...
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

--->>>>> Test 4 --->>>>>
!getCurrentSize340Iterative - Iterative...
---> Current size: 9
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

--->>>>> Test 5 --->>>>>
!getCurrentSize340Recursive() - Recursive...
---> Current size: 9
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

--->>>>> Test 6 --->>>>>
!getCurrentSize340RecursiveNoHelper() - Recursive...
---> Current size: 9
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

--->>>>> Test 7 --->>>>>
!getFrequencyOf()...
---> 0-ZERO: 1
---> 1-ONE: 0
---> 2-TWO: 0
---> 4-FOUR: 3
---> 9-NINE: 2
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

!getFrequencyOf340Recursive() - Recursive...
---> 0-ZERO: 1
---> 1-ONE: 0
---> 2-TWO: 0
---> 4-FOUR: 3
---> 9-NINE: 2
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

--->>>>> Test 8 --->>>>>
!getFrequencyOf340RecursiveNoHelper() - Recursive...
---> 0-ZERO: 1
---> 1-ONE: 0
---> 2-TWO: 0
---> 4-FOUR: 3
---> 9-NINE: 2
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

--->>>>> Test 9 --->>>>>
!removeRandom340() ---> 4-FOUR
!removeRandom340() ---> 9-NINE
!Display bag: 4-FOUR 5-FIVE #-END #-BEGIN 4-FOUR 9-NINE 0-ZERO
-----------> 7 item(s) total

!removeRandom340() ---> #-BEGIN
!removeRandom340() ---> 4-FOUR
!Display bag: #-END 5-FIVE 4-FOUR 9-NINE 0-ZERO
-----------> 5 item(s) total

!removeRandom340() ---> 9-NINE
!removeRandom340() ---> #-END
!Display bag: 4-FOUR 5-FIVE 0-ZERO
-----------> 3 item(s) total

!removeRandom340() ---> 0-ZERO
!removeRandom340() ---> 5-FIVE
!Display bag: 4-FOUR
-----------> 1 item(s) total

Asmt04_Run2.txt

----- LINKED BAG 340 C++-----

--->>>>> Test 1 --->>>>>
!add()... #-END 5-FIVE 4-FOUR 4-FOUR 3-THREE 2-TWO 1-ONE 0-ZERO #-BEGIN
!Display bag: #-BEGIN 0-ZERO 1-ONE 2-TWO 3-THREE 4-FOUR 4-FOUR 5-FIVE #-END
-----------> 9 item(s) total

--->>>>> Test 2 --->>>>>
!removeSecondNode340()...
!removeSecondNode340()...
!Display bag: #-BEGIN 2-TWO 3-THREE 4-FOUR 4-FOUR 5-FIVE #-END
-----------> 7 item(s) total

!removeSecondNode340()...
!removeSecondNode340()...
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END
-----------> 5 item(s) total

--->>>>> Test 3 --->>>>>
!addEnd340()...
!addEnd340()...
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR
-----------> 7 item(s) total

!addEnd340()...
!addEnd340()...
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

--->>>>> Test 4 --->>>>>
!getCurrentSize340Iterative - Iterative...
---> Current size: 9
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

--->>>>> Test 5 --->>>>>
!getCurrentSize340Recursive() - Recursive...
---> Current size: 9
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

--->>>>> Test 6 --->>>>>
!getCurrentSize340RecursiveNoHelper() - Recursive...
---> Current size: 9
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

--->>>>> Test 7 --->>>>>
!getFrequencyOf()...
---> 0-ZERO: 1
---> 1-ONE: 0
---> 2-TWO: 0
---> 4-FOUR: 3
---> 9-NINE: 2
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

!getFrequencyOf340Recursive() - Recursive...
---> 0-ZERO: 1
---> 1-ONE: 0
---> 2-TWO: 0
---> 4-FOUR: 3
---> 9-NINE: 2
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

--->>>>> Test 8 --->>>>>
!getFrequencyOf340RecursiveNoHelper() - Recursive...
---> 0-ZERO: 1
---> 1-ONE: 0
---> 2-TWO: 0
---> 4-FOUR: 3
---> 9-NINE: 2
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total

--->>>>> Test 9 --->>>>>
!removeRandom340() ---> #-END
!removeRandom340() ---> 4-FOUR
!Display bag: 4-FOUR 5-FIVE #-BEGIN 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 7 item(s) total

!removeRandom340() ---> 4-FOUR
!removeRandom340() ---> 9-NINE
!Display bag: #-BEGIN 5-FIVE 4-FOUR 9-NINE 0-ZERO
-----------> 5 item(s) total

!removeRandom340() ---> 5-FIVE
!removeRandom340() ---> #-BEGIN
!Display bag: 4-FOUR 9-NINE 0-ZERO
-----------> 3 item(s) total

!removeRandom340() ---> 9-NINE
!removeRandom340() ---> 4-FOUR
!Display bag: 0-ZERO
-----------> 1 item(s) total
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.