which implementation stack library use in c++? [closed] - c++

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).

Related

Efficient use of std::map and std::set in c++ [closed]

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/

Whats is Container class in C++, Can any one give good example? [closed]

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 ...

Strategy Pattern at runtime? [closed]

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 have a strategy pattern, and would like to run it in a main loop in a game for example. The problem is there will be a memory leak If I'm not deleting the instance, and I also would like to use that instance somewhere else. How can I deal with memory allocation/deallocation in a strategy pattern.
CompressionContext *ctx = new CompressionContext();
//we could assume context is already set by preferences
ctx->setCompressionStrategy(new ZipCompressionStrategy());
//get a list of files
ctx->createArchive(fileList);
Use an std::shared_ptr<CompressionContextBase> instead of a CompressionContextBase* (i.e. a raw pointer).
Edit: This is just a suggestion, based on the information you provided, there may be other smart pointer implementations with different semantics, such as e.g. unique_ptr, which might be more suited. As #akappa suggests, you may want to read up on the topic more, to make a better decision -- again, based on the information in the question, you probably want a shared_ptr but there might be additional considerations you omitted.

is std:vector<char[30]> valid, or how to achieve this? (vector of fixed sized array?) [closed]

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.

C++ Segregated Free Lists [closed]

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 need to use segregated free lists for a homework assignment and I was wondering if the STL or some other library had these already written so I don't have to reinvent the wheel?
I don't think STL has anything, but it looks like the Boost library might have it, http://www.boost.org/doc/libs/1_38_0/libs/pool/doc/interfaces/simple_segregated_storage.html
The STL implementations I've used support an allocator as a template parameter, which you could use to make a container use your segregated free list, but you'd still be writing your own.