deque

Code golf: c++ deque->vector

I'm coding in C++ What is the shortest function of: template<T> std::vector<T> make_copy(const deque<T>& d) { // your code here } ? ...

STL deque accessing by index is O(1)?

I've read that accessing elements by position index can be done in constant time in a STL deque. As far as I know, elements in a deque may be stored in several non-contiguous locations, eliminating safe access through pointer arithmetic. For example: abc->defghi->jkl->mnop The elements of the deque above consists of a single character....

[C++] Deque of user-defined structures

I've got a user-defined structure struct theName and I want to make a deque of these structures (deque<theName> theVar). However when I try to compile I get this error: In file included from main.cpp:2: Logger.h:31: error: ISO C++ forbids declaration of ‘deque’ with no type Logger.h:31: error: expected ‘;’ before ‘<’ token Why can't I...

C++ union assignment, is there a good way to do this?

I am working on a project with a library and I must work with unions. Specifically I am working with SDL and the SDL_Event union. I need to make copies of the SDL_Events, and I could find no good information on overloading assignment operators with unions. Provided that I can overload the assignment operator, should I manually sift thro...

std::deque: How do I get an iterator pointing to the element at a specified index?

I have a std::deque, and I want to insert an element at a specified index (I'm aware that std::list would be better at this). The deque::insert() function takes an iterator to specify the location to insert. Given an index, how can I get an iterator pointing to that location, so that I can pass that iterator to insert()? For example: ...

Reversing a circular deque without a sentinel

Hey Stackoverflow I'm working on my homework and I'm trying to reverse a circular-linked deque without a sentinel. Here are my data structures: struct DLink { TYPE value; struct DLink * next; struct DLink * prev; }; struct cirListDeque { int size; struct DLink *back; }; Here's my approach to reversing the deque: void revers...

Mistake in display and insert methods (double-ended queue)

1) My problem when i make remove from right or left program will be remove true but when i call diplay method the content wrong like this I insert 12 43 65 23 and when make remove from left program will remove 12 but when call display method show like this 12 43 65 and when make remove from right program will remove 23 but whe...

Instantiating C++ template functions

Hi, I am facing a few problems with "undefined reference to " errors. I may not be able to post the code, but the declarations and the way I am calling the functions are as follows: Declarations: template <typename T> int pitch_detect(deque<T>& x, int offset, int len); template <typename T> int is_voiced( deque<T>& x, int offset, i...

Is there a way to get deque's internal storage size as vector::capacity?

I understand that both deque and vector reserve some space for growth. vector::capacity() is able to get the internal reserved space for a vector. Deque doesn't have such a member in the standard. Is there some way to get this information? ...

Using Deque.popleft as args for function

Hi, I am attempting to store a list of commands to send down a serial cable using deque in Python. My function "send_command" accepts 3 values; The command, an int. pause and a boolean wait. its definition is as follows. def send_command(self, command, pause=0, wait=False): What I would like to do is, rather than calling this functi...

Python Deque appendleft with list

Hi, I am currently creating my deque object using the following, self.CommandList = deque((['S', False, 60],['c'],['g16'],['i50'],['r30', True],['u320'],['o5000'],['b1'],['B4500'],['W1'],['l5154'],['!10'],['p2', True, 10],['e1'],['K20'],['U0'],['Y0'])) But I wish to add a similar list to the queue later but using appendleft, so it ca...

Implement an immutable deque as a balanced binary tree?

I've been thinking for a while about how to go about implementing a deque (that is, a double-ended queue) as an immutable data structure. There seem to be different ways of doing this. AFAIK, immutable data structures are generally hierarchical, so that major parts of it can be reused after modifying operations such as the insertion or ...

Reversing Doublely Linked Deque in C

I'm having trouble reversing my doublely linked deque list (with only a back sentinel) in C, I'm approaching it by switching the pointers and here is the code I have so far: /* Reverse the deque param: q pointer to the deque pre: q is not null and q is not empty post: the deque is reversed */ /* reverseCirListDeque */ void revers...

HowTo get the previous element from std::deque?

Hi there. For example I have an array with about 10 elements in it. std::deque<int> d; front_inserter(d) = 100; front_inserter(d) = 200; front_inserter(d) = 300; ... front_inserter(d) = 900; front_inserter(d) = 1000; Question: how to find 900 element, without using [] access? If the size of the massive will be changes, for example to...

What's generally the size limit to switch from a vector to a deque?

I recent wrote this post: http://stackoverflow.com/questions/3737138/how-best-to-store-very-large-2d-list-of-floats-in-c-error-handling Some suggested that I implemented my 2D list-like structure of floats as a vector, others said a deque. From what I gather vector requires continuous memory, but is hence more efficient. Obviously thi...

Problem with reading binary file to a deque

I'm writing a deque implementation with ArrayList as required by my instructor. So far the body of the class looks like this try { while (!endOfFile) { character = inputFile.readChar(); while (!character.equals('\u0003')) { if (character.equals('\u0008')) deck.removeBac...

How Do I define a Double Brackets/Double Iterator Operator, Similar to Vector of Vectors'?

I'm porting code that uses a very large array of floats, which may trigger malloc failures from c to c++. I asked a question about whether I should use vectors or deques and Niki Yoshiuchi generously offered me this example of a safely wrapped type: template<typename T> class VectorDeque { private: enum TYPE { NONE, DEQUE, VECTOR }; ...

(Relatively) Size-Safe Wrapped STL Container in C++

Bear with me because I'm self taught in C++ and am spending my limited extra time on the job to try to learn more about it (I'm a chemical engineering researcher by day). I have a pretty simple objective: 1. Make a size-safe container to store a long list of floats. 2. Make a specialized version of that container that acts as a matri...

Why do we need Deque data structures in the real world?

Can anyone give me an example of situation where a Deque data structure is needed? Please don't explain what a deque is... ...

Check maxlen of deque in python 2.6

Hi, I have had to change from python 2.7 to 2.6. I've been using a deque with the maxlen property and have been checking what the maxlen is. Apparently you can use maxlen in python 2.6, but in 2.6 deques do not have a maxlen attribute. What is the cleanest way to check what the maxlen of a deque is in python 2.6? In 2.7: from collectio...