It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
To use vector efficiently we need to reserve the memory before setting the elements. But for map and set which are not contiguous containers how we can make them fast and efficient?
I have a vector/set/map of size 10s Millions of doubles and want to add non-repeated elements. I want to make it as fast as possible.
Q1) all STL containers are already as efficient as they can be. It's up to you the programmer to choose what data structures suits the given requirement. You need to understand the pros and cons of each data structures.
Q2) Map[key] = value calls operator[] which can also be used to access elements, not just inserting, whereas insert() function is only specific to inserting. insert() has few other overloading feature not available on operator[], check http://www.cplusplus.com/reference/map/map/insert/
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to know :
DEFINITION,USE & EXAMPLE OF CONTAINER CLASS IN C++....
If you know please reply it...
"Container" is a generic term (a "concept") used in the standard to refer to containers in the standard library: vector, deque, forward_list (C++11), list, array (C++11), map, set, unordered_map (C++11), unordered_set (C++11).
Searching for these should give you plenty of documentation and examples.
EDIT
You can start e.g. on cppreference
In C++, a container class does not exist. It is a term used to name one of the container classes (classes that contains objects): std::vector, std::list, std::deque, std::set ...
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I read that The ADT stack can be implemented using
An array
A linked list
The ADT list
But when I'm using the stack I just call stack library. Which of these implementation stack library use?
std::stack is a container adapter that uses some other container as the underlying storage for the data. That defaults to std::deque, but you can specify another sequence such as std::list or std::vector if you prefer.
The requirements on the underlying container are pretty minimal -- if memory serves, it needs to support a back(), push_back(), pop_back(), size() and swap() (and the last two aren't really needed unless you use stack::size() or stack::swap(), which probably aren't all that common).
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How can I tell whether an algorithm is stable or not?..
Also, how does this algorithm Bucketsort compare to Mergesort, Quicksort, Bubblesort, and Insertionsort
?
At first glance it would seem that if your queues are FIFO then it is stable. However I think there some context from class or other homework that would help you make a more solid determination.
From wikipedia:
Stability
Stable sorting algorithms maintain the relative order of records with equal keys. If all keys are different then this distinction is not necessary. But if there are equal keys, then a sorting algorithm is stable if whenever there are two records (let's say R and S) with the same key, and R appears before S in the original list, then R will always appear before S in the sorted list. When equal elements are indistinguishable, such as with integers, or more generally, any data where the entire element is the key, stability is not an issue. However, assume that the following pairs of numbers are to be sorted by their first component:
http://en.wikipedia.org/wiki/Sorting_algorithm#Stability
As far as comparing to other algorithms. Wikipedia has a concise entry on it:
http://en.wikipedia.org/wiki/Bucket_sort#Comparison_with_other_sorting_algorithms
Also: https://stackoverflow.com/a/7341355/1416221
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I would like to have a notion of 2d arrays with one dimension fixed.
something like a growing list of char arrays of length 30.
Can i do something like vector
is that valid, or is there a way of achieving this
No: the type stored in a vector (or any other Standard Library container) must be both copyable and assignable. An array is neither.
You can (and should) use std::array (or, if your implementation doesn't support that, boost::array). The array class template provides a very lightweight container-like wrapper around an ordinary array; it can be used just like an ordinary array in most circumstances and has zero overhead (with a good implementation and with compiler optimizations turned on).
There is really no good reason to use an ordinary array (like char[30]) when you can use the array class template instead.
A std::vector of std::array sounds like a better idea.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
I have ordederd to make a function, which takes a list ex [3,4,6,1,29] and returns a list of tuples [(3,4),(4,6),(6,1),(1,29)]
This is a very easy question, it's really hard to help without defeating the purpose...
If you are allowed to use predifined functions, there is already one which can do almost all work for you (if you don't know which one, try finding it with http://www.haskell.org/hoogle/ ). Take a step back and think about the easier question how to produce a list [(3,3),(4,4),(6,6),(1,1),(29,29)].
If you can't use predefined functions, then recursion is your friend: What do you need to do for an empty list? What for a list with one element? With two elements?
Without any own effort I can't give more hints. If you're stuck, extend your question and show what you already got, and we'll try to help.