Question
C++
(a) Write C++ code to create an empty unordered_map container with bucket_count or capacity equal to 15013, and then insert t
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include<bits/stdc++.h>
using namespace std;

int main(){

// initialize unordered map
unordered_map<string,int>mp;

// assign data to it
mp["Johny"]=2502;
mp["Ashley"]=8765;
mp["Tony"]=3341;
mp["Jessica"]=5213;
  
cout<<mp["Johny"]<<"\n";
cout<< mp["Ashley"]<<"\n";
cout<< mp["Tony"]<<"\n";
cout<<mp["Jessica"]<<"\n";

return 0;
  
}

#include<bits/stdc++.h> using namespace std; int main() { unordered_map<string, int>mp; mp[Johny]=2502; mp[Ashley]=8765;2502 8765 3341 5213

Map are implemented via balanced binary search trees precisely Red-black trees.

Unordered_map use hashtables to store data .

Unordered maps are faster with O(1) time to fetch data, while maps take O(logn) time

Add a comment
Know the answer?
Add Answer to:
C++ (a) Write C++ code to create an empty unordered_map container with bucket_count or capacity equal...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ Write a class that will create a binary tree that can hold values of string...

    c++ Write a class that will create a binary tree that can hold values of string data type, define and implement insert, delete, search, functions, and a constructor and a destructor. Demonstrate the insertion, searching, and deletion functions in a program.

  • Use Java language You may assume that you always map strings to integers, and therefore you...

    Use Java language You may assume that you always map strings to integers, and therefore you need not worry about using generics. Here are the methods that your map must implement. void put (String key, Integer value); insert this key-value pair into the map under the following rules: If key already exists in the map, change its value to value, overwriting what was there If key is not already there, insert this key-value pair into the map. boolean containsKey(String key);...

  • Please Write the following code in C: PRELAB - Week of October 14 For this prelab...

    Please Write the following code in C: PRELAB - Week of October 14 For this prelab you will implement the following functions: List * initIntegerList() // Return empty list int insertAtHead(int k, List*) // Insert k at head int insertAtTail(int k, List*) // Insert k at tail int removeHead(List *) // Remove head and return its key int getListSize(List *) // Return number of elements in list void printHead(List *) // Print key in head void moveHeadToTail(List *) // Move...

  • Write a C program insertion and deletion functions for a max heap represented as a linked binary tree. Assume that each...

    Write a C program insertion and deletion functions for a max heap represented as a linked binary tree. Assume that each node has a parent field as well as the usual left child, right child, and key fields. -Condition : Do not use Array representation. Use the following structure. typedef struct node *treePointer; typedef struct node { int key; treePointer parent; treePointer leftChild, rightChild; }; - INPUT i k : Insert the node with the key value of k in...

  • Write a C program insertion and deletion functions for a max heap represented as a linked binary tree. Assume that each...

    Write a C program insertion and deletion functions for a max heap represented as a linked binary tree. Assume that each node has a parent field as well as the usual left child, right child, and key fields. -Condition : Do not use Array representation. Use the following structure. typedef struct node *treePointer; typedef struct node { int key; treePointer parent; treePointer leftChild, rightChild; };    - INPUT i k : Insert the node with the key value of k in...

  • I need this to be in C Write the implementation file, priority queue.c, for the interface...

    I need this to be in C Write the implementation file, priority queue.c, for the interface in the given header file, priority queue.h. Turn in your priority queue.c file and a suitable main program, main.c, that tests the opaque object. priority queue.h is attached as a file to this assignment but is also listed here for your convenience. Your implementation file should implement the priority queue using a heap data structure. Submissions that implement the priority queue without using a...

  • in C++ Code should work for all cases In this assignment you are requested to implement...

    in C++ Code should work for all cases In this assignment you are requested to implement insert, search, and delete operations for an open-addressing hash table with double hashing. Create an empty hash table of size m= 13. Each integer of the input will be a key that you should insert into the hash table. Use the double hashing function h{k, i) = (hı(k) + ih2(k)) mod 13 where hi(k)= k mod 13 and h2(k) = 1+(k mod 11). The...

  • Using C++ language, write a code to implement the "evaluate function" described below using the given...

    Using C++ language, write a code to implement the "evaluate function" described below using the given poly.cpp file and poly.h header file. (ignore the other 3 functions if asked) poly.cpp file: poly.h header file: You are asked to implement four functions for a data structure used to store polynomials. The data structure used for polynomials is a linked list that consists of terms where each term consists of a coefficient, an exponent and a pointer to the next term. A...

  • Needed in C please Write the implementation file, priority_queue.c, for the interface in the given header file, priority_queue.h. Turn in your priority_queue.c file and a suitable main program, main.c...

    Needed in C please Write the implementation file, priority_queue.c, for the interface in the given header file, priority_queue.h. Turn in your priority_queue.c file and a suitable main program, main.c, that tests the opaque object. priority_queue.h is attached as a file to this assignment but is also listed here for your convenience. Your implementation file should implement the priority queue using a heap data structure. Submissions that implement the priority queue without using a heap will not receive any credit. #ifndef...

  • Write in C++: Please create a shopping list using the STL list container, then follow the...

    Write in C++: Please create a shopping list using the STL list container, then follow the following instructions. Create an empty list. Append the items, "eggs," "milk," "sugar," "chocolate," and "flour" to the list. Print the list. Remove the first element from the list. Print the list. Insert the item, "coffee" at the beginning of the list. Print the list. Find the item, "sugar" and replace it with "honey." Print the list. Insert the item, "baking powder" before "milk" in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT