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

  • Home
  • SEARCH
  • 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 7034529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:11:49+00:00 2026-05-28T01:11:49+00:00

EDIT: Sorry, this turned out just to be my mistake in initializing in the

  • 0

EDIT: Sorry, this turned out just to be my mistake in initializing in the code below.

const int kDigits = 7;
std::vector<int> number(kDigits);
for (int i = kDigits - 1; i >= 0; i--) {
    number[i] = i + 1;
}

The vector number is initialized to 7, 6, 5, 4, 3, 2, 1.
My goal is to generate the permutations in decreasing order:
7654321
7654312
7654231
7654213
7654132

This code works:

do {
...
}
while (std::prev_permutation(number.rbegin(), number.rend()));

However, I’m not understanding why. Since 7654321 is the largest lexicographical permutation, shouldn’t while (std::prev_permutation(number.begin(), number.end())); (no reverse iterators) generate it correctly, since it would generate the previous permutation in order? However, this returns false on the first try, even though it should generate the “lower permutation.”

Also, in the code shown above, since it uses reverse iterators, my mind interprets it as finding the previous permutation of 1234567 (7654321 backwards), which seems to me should have none.

Thanks so much for the help in advance! I look forward to figuring out what I misinterpreted / what I’m missing.

  • 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-05-28T01:11:50+00:00Added an answer on May 28, 2026 at 1:11 am

    The vector number is initialized to 1,2,3,4,5,6,7, not 7,6,5,4,3,2,1. That’s why your code works.

    If you want it initialized to 7,6,5,4,3,2,1, you need to fix the initialization routine.

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

Sidebar

Related Questions

Sorry if this question will sound too chaotic, feel free to edit it. I
IMPORTANT EDIT: Sorry everyone, i made a big mistake in the structure. char *name;
Edit: I fixed the problem by just starting from scratch. Sorry to waste y'alls
Sorry if this is a dup, my searching turned up nothing. I am using
EDIT: SORRY! Turns out that I'm an idiot. The exception was being thrown from
I'm trying to figure out why this code doesn't work in C# and how
I'd like an efficient method that would work something like this EDIT: Sorry I
Edit: Sorry guys, but I wasn't seeing this behavior when I came into work
EDIT Sorry I forgot the most important part here. Each key can have more
Is there a .net equivalent to the C++ unexpected()/set_unexpected() functionality? Edit: Sorry--I omitted some

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.