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 8665559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:30:33+00:00 2026-06-12T17:30:33+00:00

How to shuffle stl list of pointers in C++ ? I have stl vector

  • 0

How to shuffle stl list of pointers in C++ ?
I have stl vector of pointers on class Player and I shuffle like

std::random_shuffle(players.begin(), players.end());

Is there already algorithm for shuffle list without requiring Random Access or I need to convert list to vector => shuffle => back to list ? Is there more elegant solution ?

  • 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-12T17:30:35+00:00Added an answer on June 12, 2026 at 5:30 pm

    The random shuffle algorithm swaps a specific element with a randomly chosen one. It would be very inefficient to repeatedly traverse the list to get the elements (namely it would be an O(n^2) operation).

    That’s why it would be better (faster) to copy your list to an array once, do a random shuffle and possibly restore the list. That would be 3*n traversals, which is still O(n).

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

Sidebar

Related Questions

i have this function that will shuffle a list of images, when i press
C++. Visual Studio 2010. I have a std::vector V of N unique elements (
I would like to shuffle values in an HashMap. I have following type of
I need a shuffle albums algorithm for my audio player like in foobar2k. So
I have a utility function that will shuffle the elements of any Vector, but
Is there a well-known solution to the following problem? You have a vector of
I am wondering if there is a best way to shuffle a list of
Is there a simple shuffle function for Scala lists? If not, whats the simplest
Anyone have any idea why shuffle() would only return 1 item? when using: $array2
Is there a way to trigger a shuffle in windows wallpaper slideshow? Preferably something

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.