Shuffle list in c++

Asked

Viewed 215 times

-1

I want to know how I can, given a list, shuffle the order of the elements in it. The type structure of the list I want to shuffle is as follows.

struct exemplo {
  int I;
  int O;
  int V;
  struct exemplo *prox;
}
  • I don’t understand your question. It’s too open and unclear. What is your structure like? Does your list node contain an object and pointer to the next node? Or a vector and pointer to the next node? It’s simply chained?

  • In the structure I have 3 integer values, and the pointer to the next node.

  • Then the examples that I could find the structures had 1 value only in the structure, then passed to the vector and shuffled and returned the values to the list

  • [Edit] your question enter the relevant information

  • Okay, I’ll edit the question

  • Don’t you mean to say that you want to create a function that takes a list and, when you finish the execution of the function, the order of the elements is drawn? That’s what it is to shuffle the elements, would be the elements that are already inside the list?

  • Yes, I already have a list, so I want to shuffle the elements. Then the node of the list will contain these elements

Show 2 more comments

1 answer

0

Probably use the function Rand() that generates a number from 1 to 3, then with these numbers exchange the elements that have in this list of random order

Browser other questions tagged

You are not signed in. Login or sign up in order to post.