looping through a deque using a recursive function in c++ [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am trying to create a recursive function in c++ that takes in a deque of integers as a parameter, loops through each element one by one, and returns the deque. I have found a few previous posts on StackOverflow that do something similar, but I am unable to understand what is happening in their answers. I am relatively new to C++. While it may be far easier and more efficient to do this by using an iterative algorithm, I am required to use recursion (it's an assignment question). Help is greatly appreciated.

it should be something like this
deque <int> x;
void Calc (deque <int> d){
if (d.empty()) return;
x.push_back(d.front());
d.pop_front();
Calc(d);
}

Related

How to create an empty std::map object? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I tried this:
std::map<int,int> m;
and it works -- m becomes an empty map. But this approach may not work if the compiler choose to not initialize m to an empty map by default. Better solution?
Any better solution?
Taking your question literally, no. There is no better solution.
This will create a default constructed, and therefore empty std::map<int,int>.
std::map<int,int> m;

In C++ an algorithm that can be used to determine whether a Stack object S has exactly one element [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Develop an algorithm that can be used to determine whether a Stack object S has exactly one element.
I am not a programmer, I choose this course as an elective to see if I would be interested. I don't know where to begin with this question.
You most likely want to check the documentation of C++ on stacks. This took no time to find:
http://www.cplusplus.com/reference/stack/stack/size/
Your function has to return stack.size() == 1. If the question is asking to develop an algorithm based on the size in memory the stack size allocates then it's slightly more involved.

storing contents in vectors in C++ language [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How do you store contents in a vector and then sort them without creating a class?
Doing a class project and it requires to not use a class. The books are not helping.
This page has a good example, assuming you can put all of the elements in the vector at once. If you need to put them in one at a time, use std::vector::push_back.
Something like std::vector<std::string> v; v.push_back("hello"); std::sort(v.begin(), v.end());. Get better books.

How do you implement quicksort with the pivot in the middle position and what is this variation called? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How do you implement quicksort with the pivot in the middle position and not in the last/first one?
It seems to be Quicksort, as the function name suggests; however there apparently is no recursive call to sort the parts after pivoting. I suggest moving the output out of the function quickSort and add recursive calls to parts of the array after the poivoting and rearrangement.
The answer lies in the Wikipedia article linked in this post.

data type of a and b in map<int,int> a,b [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to learn c++. I was struck at map in c++. Can someone qualitatively explain me what is a map and where is it more often used?
You are wrong about the internals of std::map - it uses a data structure with O(log n) insertion, query and delete times. IIRC, it's a red-black tree. To answer your question, the objects stored are of type map<int,int>::value_type which is std::pair<const int, int>. Here's the ref.