Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9000483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:19:00+00:00 2026-06-16T00:19:00+00:00

I have two questions but they are interlinked.: part:a-> I have been trying to

  • 0

I have two questions but they are interlinked.:

part:a->

I have been trying to display the elements of vector in reverse order. But nothing is working. I have used iterotar like;

for (it=vec.end(); it!=vec.begin(); --it){ 
// it is iterator not reverse_iterator.
// do work
}

P.S I am not much familiar with iterators. I have used them for the first time today to
display elem in reverse order.

also tried;

for (int i=vec.size(); i!=0; i--){
//display
}

No matter what I do it always display the elem in same order as they are present i.e not in the reverse order.

part_b->

Is there any way that I can store the output of a recursive function direct into a vector. like the code is:
I know this does not work. I have tried but just giving you an idea
what I am upto.

#include <iostream>
using namespace std;
#include "vector"

int func(int num);
vector <int> vec;

int main() {
    int num=34;
    // I know this would not work. But is there any possibilitiy that
    // I can store the output in a vector.
    vec = binary(num);                          

    // trying to display the vector.        
    for (int i=vec.size();i!=0;i--) {
        cout<<vec[i]<<" ";
    } // not working for reverse display.
} //main.

int func(int num) {
    if (num==1) {
        //vec.push_back(1);
        return 1;
    }
    else if(num==0) {
        //vec.push_back(0);
        return 0;
    }
    else {
        //vec.push_back(input%2);
        return binary(input/2);
    }
} //func.

I hope you do unnderstand the question. if I am able to do the part b the there is no need to reverse the elem of the vector.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:19:01+00:00Added an answer on June 16, 2026 at 12:19 am

    The standard solution uses reverse iterators:

    for (auto it = v.rbegin(); it != v.rend(); ++it)
    {
        if (it != v.rbegin()) { std::cout << ' '; }
        std::cout << *it;
    }
    

    Alternatively, you can use indices, but keep the “reversal” idiom and increment the index:

    for (std::size_t i = 0; i != v.size(); ++i)
    {
        if (i != 0) { std::cout << ' '; }
        std::cout << v[v.size() - i - 1];
    }
    

    Note that reverse iterators are literally just doing something very similar to the explicit loop under the hood. In particular, the base() member function of a reverse iterator gives you the corresponding ordinary iterator offset by one, just as we have a - 1 in the index computation. (E.g. rbegin() is just end() under the hood, but decrements by one upon dereferencing.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have actually two questions but they are kind of related so here they
I have two questions with regards to Bullet, but they are related. In the
I have two questions regarding RewriteRule, but they're both closely related so I hope
I actually have two questions today, but they are both small :-) 1) Where
I have two questions.They both are concerning a void in C++,which I am trying
guys I have two question to ask, they're easy, but bothering me for a
I am not sure if people find this obvious but I have two questions:
i'm searching about image filters using ios5 sdk but i have two questions: For
Here are two different questions but I think they are related. When using Git,
I actually have two questions regarding the same problem but I think it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.