C multiset return key at position

0 votes
According to the documentation, the multiset data object contains property ordering.

As a result, for a multiset named, say, ms, it should be clear how to get the set element at a given location I such that 0 = I ms.size ().

I attempted to access these items as ms[i].

The language, however, argues that multiset does not accept subscripts.

How can I access element I in a multiset using syntax?
Jun 27, 2022 in C++ by Nicholas
• 7,760 points
227 views

1 answer to this question.

0 votes
A set (or multiset) is typically represented as a tree.

As a result, key access is fairly efficient.

It is not possible to gain access using an index.

(Unlike an array, a tree does not provide random access to nodes.)

Of course, there are ingenious combinations (trees with all nodes saved in an array), but not for std::.

set vs std::multiset
answered Jun 27, 2022 by Damon
• 4,960 points

Related Questions In C++

0 votes
0 answers

How to find if a given key exists in a C++ std::map

I'm trying to check if a given ...READ MORE

Jul 14, 2022 in C++ by Nicholas
• 7,760 points
604 views
+1 vote
0 answers

Using push_back vs at in a vector in C++

I'm not sure how to use vectors in C++.  It has to do with the vector's push back technique.  I used push back to insert entries into the vector in the first programme.  I used at() to insert entries into the vector in the second application. #include <iostream> #include <vector> #include <string> using namespace std; int main ...READ MORE

Jul 22, 2022 in C++ by Nicholas
• 7,760 points
239 views
0 votes
0 answers

Is there a default return value of C++ functions?

I'm amazed that a file with the  ...READ MORE

Jul 25, 2022 in C++ by Nicholas
• 7,760 points
313 views
0 votes
0 answers

Insert object at index of vector c++

I have to add a new item to the existing object vector.  Although I am aware that an iterator must be used, I am not entirely sure how it operates. I need to insert a new item by name in the precise index that I found after some searching into an alphabetically sorted vector.  I have this, then. vector<Person>people; int index =54; Person temp; people.push_back(temp);//insert at end of ...READ MORE

Aug 5, 2022 in C++ by Nicholas
• 7,760 points
470 views
0 votes
1 answer

Use of multisets in C++ [duplicate]

Because a multi-set does not need the storage of single-element objects.  You're considering storing anything in a multi-set, such as a string.  But it is not its intended use.  You may use whatever struct you want and compare it to a single element in the struct. As an example: struct PhoneBookEntry { std::string name; ...READ MORE

answered Jun 27, 2022 in C++ by Damon
• 4,960 points
260 views
0 votes
1 answer

setuptools: build shared libary from C++ code, then build Cython wrapper linked to shared libary

There is a seemingly undocumented feature of setup that ...READ MORE

answered Sep 11, 2018 in Python by Priyaj
• 58,090 points
491 views
0 votes
1 answer

setuptools: build shared libary from C++ code, then build Cython wrapper linked to shared libary

There is a seemingly undocumented feature of setup that ...READ MORE

answered Sep 21, 2018 in Python by Priyaj
• 58,090 points
2,135 views
0 votes
1 answer

How to pass large records to map/reduce tasks?

Hadoop is not designed for records about ...READ MORE

answered Sep 25, 2018 in Big Data Hadoop by Frankie
• 9,830 points
1,212 views
0 votes
1 answer

In C++ abs( *a - *b) does not return absolute value of negative number

On the first line, you reallocated *a, and it is now utilising that new value on the second line.  int origa = *a; *a = abs(origa + ...READ MORE

answered Jun 27, 2022 in C++ by Damon
• 4,960 points
442 views
0 votes
1 answer

Declare abstract class in c++

An abstract class is one that is intended to be used as a base class .  At least one pure virtual function exists in an abstract class.  A pure virtual function is declared in the class declaration by using a pure specifier (= 0) in the declaration of a virtual member function. Here is an example of an abstract class: class AB { public: virtual void f() ...READ MORE

answered May 31, 2022 in C++ by Damon
• 4,960 points
384 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP