
Concept explainers
BST - Binary Search Tree
- implement a BSTNode ADT with a data attribute and two pointer attributes, one for the left child and the other for the right child. Implement the usual getters/setters for these attributes
-implement a BST as a link-based ADT whose data will be Dollar objects - the data will be inserted based on the actual money value of your Dollar objects as a combination of the whole value and fractional value attributes.
- BST, implement the four traversal methods as well as methods for the usual search, insert, delete, print, count, isEmpty, empty operations and any other needed.
-
BST - Binary Search Tree
- implement a BSTNode ADT with a data attribute and two-pointer attributes, one for the left child and the other for the right child. Implement the usual getters/setters for these attributes
-implement a BST as a link-based ADT whose data will be Dollar objects - the data will be inserted based on the actual money value of your Dollar objects as a combination of the whole value and fractional value attributes.
- BST, implement the four traversal methods as well as methods for the usual search, insert, delete, print, count, isEmpty, empty operations and any other needed.
- pgm will have at least 10 Dollar objects created from data specified in your main to seed the tree.
- Read the data of your main to create your Dollar
database using the BST. - Also, create an output file to write program output as specified in one or more instructions below.
- Perform adequate data validation when reading data from the user into the tree - if any data item is invalid, ignore the data item and continue to next item but print a message to output (both screen and output file) to indicate which data items were ignored.
- Provide interactivity for the user to add/search/delete nodes from the console after the data has been seeded into the application, including data validation.
USE THIS CLASS:
class Currency {
protected:
int whole;
int fraction;
virtual string currName() = 0;
public:
Currency() {
whole = 0;
fraction = 0;
}
Currency(double value) {
if (value < 0)
throw "Invalid value";
whole = int(value);
fraction = round(100 * (value - whole));
}
Currency(const Currency &obj) {
whole = obj.whole;
fraction = obj.fraction;
}
~Currency() {}
void setWhole(int setW) {
if (setW >= 0)
whole = setW;
}
void setFraction(int setFrac) {
if (setFrac >= 0 && setFrac < 100)
fraction = setFrac;
}
int getWhole() { return whole; }
int getFraction() { return fraction; }
void add(const Currency *obj) {
whole += obj->whole;
fraction += obj->fraction;
if (fraction > 100) {
whole++;
fraction %= 100;
}
}
void subtract(const Currency *obj) {
if (!isGreater(*obj))
throw "Invalid Subtraction";
whole -= obj->whole;
if (fraction < obj->fraction) {
fraction = fraction + 100 - obj->fraction;
whole--;
} else {
fraction -= obj->fraction;
}
}
bool isEqual(const Currency &obj) {
return obj.whole == whole && obj.fraction == fraction;
}
bool isGreater(const Currency &obj) {
if (whole < obj.whole)
return false;
if (whole == obj.whole && fraction < obj.fraction)
return false;
return true;
}
void print() { cout << whole << "." << fraction << " " << currName() << " "; }
};

Step by stepSolved in 2 steps with 1 images

- Program 3: Binary Search Tree Program Objective The primary objective of this program is to learn to implement binary search trees and to combine their functionalities with linked lists. Program Description In a multiplayer game, players' avatars are placed in a large game scene, and each avatar has its information in the game. Write a program to manage players' information in a multiplayer game using a Binary Search (BS) tree for a multiplayer game. A node in the BS tree represents each player. Each player should have an ID number, avatar name, and stamina level. The players will be arranged in the BS tree based on their ID numbers. If there is only one player in the game scene, it is represented by one node (root) in the tree. Once another player enters the game scene, a new node will be created and inserted in the BS tree based on the player ID number. Players during the gameplay will receive hits that reduce their stamina. If the players lose all their stamina, they vanish from the…arrow_forwardA queue and a deque data structure are related concepts. Deque is an acronym meaning "double-ended queue." With a deque, you may insert, remove, or view from either end of the queue, which distinguishes it from the other two. Use arrays to implement a dequearrow_forwardThe specifications for the Sorted List ADT state that the item to bedeleted is in the list.1. Rewrite the specification for DeleteItem so that the listis unchanged if the item to be deleted is not in the list.2. Implement DeleteItem as specified in (a) using anarray-based implementation.3. Implement DeleteItem as specified in (a) using alinked implementation.4. Rewrite the specification for DeleteItem so that allcopies of the item to be deleted are removed if they exist.5. Implement DeleteItem as specified in (d) using anarray-based implementation.6. Implement DeleteItem as specified in (d) using alinked implementation.arrow_forward
- def to tree (obj: Union [int, List])-> Optional [Tree]: """Return the Tree which represents. Return None if is not a valid representation of a Tree. You may not access Tree attributes directly, since they're private. This function can be implemented only using the Tree initializer. >>> t = to_tree ([1, [2, [5], [6]], [3, [7], [8, [10]]], [4, [9]]]) >>> t._root 1 >>> t._subtrees [0]._root 2 >>> t._subtrees [1]._root 3 >>> t._subtrees [2]._root 4arrow_forwardSet and Map class templates are similar in the sense that they both use binary search trees. The difference is Set is used to store only keys while Map is used to store (key, value) pairs. Group of answer choices True Falsearrow_forward1. Write code to define LinkedQueue<T> and CircularArrayQueue<T> classes which willimplement QueueADT<T> interface. Note that LinkedQueue<T> and CircularArrayQueue<T>will use linked structure and circular array structure, respectively, to define the followingmethods.(i) public void enqueue(T element); //Add an element at the rear of a queue(ii) public T dequeue(); //Remove and return the front element of the queue(iii) public T first(); //return the front element of the queue without removing it(iv) public boolean isEmpty(); //Return True if the queue is empty(v) public int size(); //Return the number of elements in the queue(vi) public String toString();//Print all the elements of the queuea. Create an object of LinkedQueue<String> class and then add some names of your friendsin the queue and perform some dequeue operations. At the end, check the queue sizeand print the entire queue.b. Create an object from CircularArrayQueue<T> class and…arrow_forward
- Design an implementation of an Abstract Data Type consisting of a set with the following operations: insert(S, x) Insert x into the set S. delete(S, x) Delete x fromthe set S. member(S, x) Return true if x ∈ S, false otherwise. position(S, x) Return the number of elements of S less than x. concatenate(S, T) Set S to the union of S and T, assuming every element in S is smaller than every element of T. All operations involving n-element sets are to take time O(log n).arrow_forwardIN C LANGUAGE When inserting a node into a linked list, where (in memory) will that node be placed if there is no overflow? A) The location of the AVAIL pointer B) The next contiguous spot of memory from the last node C) The very end of the contiguous memory block D) A randomized memory locationarrow_forwardWord frequencies (dictionaries) Implement the build_dictionary() function to build a word frequency dictionary from a list of words. Ex: If the words list is: ["hey", "hi", "Mark", "hi", "mark"] the dictionary returned from calling build_dictionary(words) is: {'hey': 1, 'hi': 2, 'Mark': 1, 'mark': 1} half answered: code: def build_dictionary(words):# The frequencies dictionary will be built with your code below.# Each key is a word string and the corresponding value is an integer # indicating that word's frequenc # The following code asks for input, splits the input into a word list, # calls build_dictionary(), and displays the contents sorted by key.if __name__ == '__main__':words = input().split()your_dictionary = build_dictionary(words)sorted_keys = sorted(your_dictionary.keys())for key in sorted_keys:print(key + ': ' + str(your_dictionary[key]))arrow_forward
- QUESTION 5 Stack can be implemented using and O a. Array and Binary Tree O b. Linked List and Graph O c. Queue and Linked List O d. Array and Linked List QUESTION 6 Postfix form of following expression. D+ (E * F) O a. EF * D+ b. DEF +* O c. DEF * + d. EFD *+arrow_forwardCreate a function that uses Node * pointing to root of AVL Tree as an input and returns the height of the AVL tree in O(log(n)).arrow_forwardSimple linkedlist implementation please help (looks like a lot but actually isnt, everything is already set up for you below to make it EVEN easier) help in any part you can be clear Given an interface for LinkedList- Without using the java collections interface (ie do not import java.util.List,LinkedList, Stack, Queue...)- Create an implementation of LinkedList interface provided- For the implementation create a tester to verify the implementation of thatdata structure performs as expected Build Bus Route – Linked List- You’ll be provided a java package containing an interface, data structure,implementation shell, test harness shell below.- Your task is to:o Implement the LinkedList interface (fill out the implementation shell)o Put your implementation through its paces by exercising each of themethods in the test harnesso Create a client (a class with a main) ‘BusClient’ which builds a busroute by performing the following operations on your linked list:o§ Create (insert) 4 stations§…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





