Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 21.6, Problem 21.6.1CP
Program Plan Intro
Map:
Map is an interface which contains values on the basis of key and a value pair and represents a mapping between them. Each key and a value pair in the map are unique.
A map can be of three types: HashMaps, LinkedMaps and TreeMaps.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
using namespace std;
class SinglyLinkedListNode {
// INSERT YOUR CODE HERE
};
class SinglyLinkedList {
public:
SinglyLinkedListNode *head;
SinglyLinkedListNode *tail;
SinglyLinkedList() {
this->head = nullptr;
this->tail = nullptr;
}
voidinsert_node(intnode_data) {
// INSERT YOUR CODE HERE
}
};
void free_singly_linked_list(SinglyLinkedListNode* node) {
// INSERT YOUR CODE HERE
}
// Complete the has_cycle function below.
/*
* For your reference:
*
* SinglyLinkedListNode {
* int data;
* SinglyLinkedListNode* next;
* };
*
*/
bool has_cycle(SinglyLinkedListNode* head) {
SinglyLinkedListNode* temp = head;
bool isCycle = false;
while (temp != nullptr)
{
// INSERT YOUR CODE HERE
}
}
int main()
{
// INSERT YOUR CODE HERE TO TEST YOUR CODE
return0;
}
using namespace std;
class SinglyLinkedListNode {
// INSERT YOUR CODE HERE
};
class SinglyLinkedList {
public:
SinglyLinkedListNode *head;
SinglyLinkedListNode *tail;
SinglyLinkedList() {
this->head = nullptr;
this->tail = nullptr;
}
voidinsert_node(intnode_data) {
// INSERT YOUR CODE HERE
}
};
void free_singly_linked_list(SinglyLinkedListNode* node) {
// INSERT YOUR CODE HERE
}
// Complete the has_cycle function below.
/*
* For your reference:
*
* SinglyLinkedListNode {
* int data;
* SinglyLinkedListNode* next;
* };
*
*/
bool has_cycle(SinglyLinkedListNode* head) {
SinglyLinkedListNode* temp = head;
bool isCycle = false;
while (temp != nullptr)
{
// INSERT YOUR CODE HERE
}
}
int main()
{
// INSERT YOUR CODE HERE TO TEST YOUR CODE
return0;
}
Help in C++ please:
Write a program (in main.cpp) that:
Prompts the user for a filename containing node data.
Outputs the minimal spanning tree for a given graph.
You will need to implement the createSpanningGraph method in minimalSpanTreeType.h to create the graph and the weight matrix.
There are a few tabs:
main.cpp, graphType.h, linkedList.h, linkedQueue.h, queueADT.h, minimalSpanTreeType.h, and then two data files labeled: CH20_Ex21Data.txt, CH20Ex4Data.txt
Chapter 21 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 21.2 - Prob. 21.2.1CPCh. 21.2 - Prob. 21.2.2CPCh. 21.2 - Prob. 21.2.3CPCh. 21.2 - Prob. 21.2.4CPCh. 21.2 - Prob. 21.2.5CPCh. 21.2 - Suppose set1 is a set that contains the strings...Ch. 21.2 - Prob. 21.2.7CPCh. 21.2 - Prob. 21.2.8CPCh. 21.2 - What will the output be if lines 67 in Listing...Ch. 21.2 - Prob. 21.2.10CP
Ch. 21.3 - Prob. 21.3.1CPCh. 21.3 - Suppose you need to write a program that stores...Ch. 21.3 - Suppose you need to write a program that stores...Ch. 21.3 - Suppose you need to write a program that stores a...Ch. 21.3 - Prob. 21.3.5CPCh. 21.3 - Prob. 21.3.6CPCh. 21.4 - Prob. 21.4.1CPCh. 21.4 - Prob. 21.4.2CPCh. 21.5 - Prob. 21.5.1CPCh. 21.5 - Prob. 21.5.2CPCh. 21.5 - Prob. 21.5.3CPCh. 21.6 - Prob. 21.6.1CPCh. 21.6 - Prob. 21.6.2CPCh. 21.6 - Prob. 21.6.3CPCh. 21.6 - Prob. 21.6.4CPCh. 21.7 - Prob. 21.7.1CPCh. 21.7 - Prob. 21.7.2CPCh. 21 - Prob. 21.1PECh. 21 - (Display nonduplicate words in ascending order)...Ch. 21 - Prob. 21.3PECh. 21 - (Count consonants and vowels) Write a program that...Ch. 21 - Prob. 21.6PECh. 21 - (Revise Listing 21.9, CountOccurrenceOfWords.java)...Ch. 21 - Prob. 21.8PECh. 21 - Prob. 21.9PE
Knowledge Booster
Similar questions
- ? mapMystery ♡ Language/Type: What is the output of the following code? Map map = new TreeMap(); map.put("K", "Schwarz"); map.put("C", "Lee"); map.put("M", "Sahami"); map.put("M", "Stepp"); map.remove("Stepp"); map.remove("K"); map.put("J", "Cain"); map.remove("C, Lee"); System.out.println(map); output a. O {J-Cain, M=Sahami} b. O {J-Cain, C=Lee, M=Sahami, M=Stepp} c. O {C-Lee, J-Cain, M=Stepp} d. O {C-Lee, J-Cain, M=Stepp, M=Sahami} (order shuffled) Java Map TreeMap collectionsarrow_forward//give the output of the following program and draw the link list. struct node{ int info; struct node *link;};typedef struct node *nodePTR;void insort(nodePTR*,struct Info);nodePTR getnode();int main(void){nodePTR p=NULL,head=NULL,save;inti; for(i=0;i<3;i++){ insort (&head,i+5);}save=head;do{ printf("%d",save->info); save=save->link;}while(save!=NULL); return0;}nodePTR getnode(){nodePTR q;q=(nodePTR)malloc(sizeof(struct node));return q;}void insort(NODEPTR *head , int x){ NODEPTR p,q,r; q=NULL; for(p=*head; p!=NULL &&x>p->info; p=p->link) q=p; if(q=NULL) { p=getnode(); p->info=x; p->link=head; head=p; }else{ r=getnode(); q->link=r; r->info=x; r->link=p; }}arrow_forwardPlease fill in the code gaps if possible. This problem has been giving me trouble. Any help is appreciated. public class Node { private String element; // we assume elements are character strings private Node next; /* Creates a node with the given element and next node. */ public Node(String s, Node n) { //fill in body } /* Returns the element of this node. */ public String getElement() { //fill in body } /* Returns the next node of this node. */ public Node getNext() { //fill in body } // Modifier methods: /* Sets the element of this node. */ public void setElement(String newElem) { //fill in body } /* Sets the next node of this node. */ public void setNext(Node newNext) { //fill in body } }arrow_forward
- What does this part of code do? void addRecord(Node *& head, Node *& tail, string name, double balance){ Node *newNode = new Node; newNode->name = name; newNode->balance = balance; newNode->next = NULL; newNode->prev = NULL; // If list is empty, make newNode the first node if(head == NULL){ head = newNode; tail = newNode; } else{ Node *temp = head; // Loop through list until temp->next is NULL while(temp->next != NULL){ temp = temp->next; } temp->next = newNode; newNode->prev = temp; tail = newNode; }} /*arrow_forwardNonearrow_forwardComplete the //comments and TODOs in c++ #include "LinkedList.h" using namespace std; // Add a new node to the list void LinkedList::insert(Node* prev, int newKey){ //Check if head is Null i.e list is empty if(head == NULL){ head = newNode; head->key = newKey; head->next = NULL; } // if list is not empty, look for prev and append our node there elseif(prev == NULL) { Node* newNode = newNode; newNode->key = newKey; newNode->next = head; head = newNode; } else{ Node* newNode = newNode; newNode->key = newKey; newNode->next = prev->next; prev->next = newNode; } } // TODO: SILVER PROBLEM // Delete node at a particular index bool LinkedList::deleteAtIndex(int n) { boolisDeleted = false; if(head == NULL){ cout<<"List is already empty"<<endl; returnisDeleted; } // Special case to delete the head if (n == 0) { //TODO } Node *pres = head; Node *prev = NULL; // TODO returnisDeleted; } // TODO: GOLD PROBLEM // Swap the first and last nodes (don't…arrow_forward
- typedef struct node{int data;struct node *left,*right;}BST;The node structure of BST is shown above. Please design an efficient algorithm to return the maximum keyword value in BST. Completion function: int findmax (BST *T)arrow_forwardC++ DATA STRUCTURES Implement the TNode and Tree classes. The TNode class will include a data item name of type string,which will represent a person’s name. Yes, you got it right, we are going to implement a family tree!Please note that this is not a Binary Tree. Write the methods for inserting nodes into the tree,searching for a node in the tree, and performing pre-order and post-order traversals.The insert method should take two strings as input. The second string will be added as a child node tothe parent node represented by the first string. Hint: The TNode class will need to have two TNode pointers in addition to the name data member:TNode *sibling will point to the next sibling of this node, and TNode *child will represent the first child ofthis node. You see two linked lists here??? Yes! You’ll need to use the linked listsarrow_forwardI have an assignment that requires me to read strings from a text file and insert them into a binary search tree. I am having a hard time reading the data from the file and passing it through a function. This is the code I have right now: struct tree_node {char *data;tree_node *left;tree_node *right;}; char **Read();tree_node *create_node(char **val); int main(){tree_node *root= NULL, *temp_node;char **val = (char**)malloc(sizeof(char*)*17);for (int i = 0; i < 17; i++) {val[i] = (char*)malloc(sizeof(char)*strlen(*val));}temp_node = create_node(val);root = insert(root, temp_node);printf("In Order: ");inorder(root);printf("\n");return 0;} char **Read() {int size;FILE *fp = fopen("in.txt", "r");fscanf(fp, "%d", &size);char** value = (char**)malloc(sizeof(char*));for(int i = 0; i < size; i++) {fscanf(fp, "%s", &value[i]);} fclose(fp);return value;} tree_node *create_node(char **val) {tree_node* temp = (tree_node*)malloc(sizeof(tree_node));for(int i = 0; i < 17; i++)for(int…arrow_forward
- Explain this code by putting comments in detail. Language used is c++. Topic is Linkedlist // void deleteByData(int data) { // if(head->data == data) { // head = head->next; // } // next = head; // Node *prev = next; // while (next != NULL) { // if (next->data == data) { // prev->next = prev->next->next; // } // prev = next; // next = next->next; // } // }; };arrow_forwardC+ Write a program that outputs the shortest distance from a given node to every other node in the graph. I NEED THESE HEADER FILES INCLUDED IN THE PROGRAM PLEASE These are the header files: graphType.h, linkedList.h, linkedQueue.h, queueADT.h, testProgGraph.cpp, unorderedLinkedList.h, weightedGraph.harrow_forwardplz change it to 8 columns and 8 rows #include <stdio.h>#include <stdlib.h>intsourceV,Vertex,Edge,time,visited[10],Graph[10][10];void DepthFirstSearch(inti){int j;visited[i]=1;printf(" %d->",i++);for(j=0;j<Vertex;j++){if(Graph[i][j]==1&&visited[j]==0)DepthFirstSearch(j);}}intmain(){inti,j,vertex1,vertex2;printf("\t\t\tGraphs\n");printf("Enter no. of edges:");scanf("%d",&Edge);printf("Enter no. of vertices:");scanf("%d",&Vertex);for(i=0;i<Vertex;i++){for(j=0;j<Vertex;j++)Graph[i][j]=0;}for(i=0;i<Edge;i++){printf("Enter the edges in V1 V2 : ");scanf("%d%d",&vertex1,&vertex2);Graph[vertex1-1][vertex2-1]=1;}for(i=0;i<Vertex;i++){for(j=0;j<Vertex;j++)printf(" %d ",Graph[i][j]);printf("\n");}printf("Enter source Vertex: ");scanf("%d",&sourceV);DepthFirstSearch(sourceV-1);return 0;}arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education