How do you walk an array?

3
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by VernonDozier

That probably means to create a loop and inspect each element. For example:

``````int array[5];
for(int i = 0; i < 5; i++)
cout << array[i] << " ";``````

we're supposed to create an array of 1000 integers, and then shuffle it so that each number appears only once, except in a random order. Our instructions say walk an array once, and then swap the number at the current index with a random index between 0 and 999. What does that mean?

we're supposed to create an array of 1000 integers, and then shuffle it so that each number appears only once, except in a random order. Our instructions say walk an array once, and then swap the number at the current index with a random index between 0 and 999. What does that mean?

"Walk" is probably a synonym for "traverse", which is to go through the array one element at a time and do whatever with that element, which in your case is to do some swapping so the array is randomized. I've never heard the term "walk". Maybe it has some technical meaning, but I doubt it. It probably means "traverse". I'd ignore the term "walk" and just focus on the best way to randomize the order of 1000 integers. There are several ways to do that and I wouldn't be surprised if there are several threads on Daniweb. Card games involve similar tasks and there are lots of threads on here dealing with good ways to shuffle cards. Here's one that may help. You'll have to tweak it to your situation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.