How do you walk an array?

Recommended Answers

All 3 Replies

with your feet :)

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.

http://www.daniweb.com/forums/thread115841.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.