0
print random array elements without duplication
How can i can print the elements of an array in an random order without printing the same element twice? Do you have a code/function for that? i struggle figuring it out.
4 odpowiedzi
+ 2
try to implement this logic:
1) keep a list of previously printed elements
2) generate random index of the array where the elements are stored
3) if the number in the selected index does NOT appear in the previously printed elements list, add it to the list and print it
4) if the elements list and previously printed elements list are of same length, return (program ended)
5) else, go back to step 2
0
okay
0
Am gonna leave this answer here, and I will come back with the solution and explain it, btw am a bit of a beginner too, so don't expect much.
0
Finally done, here is the link for it:
https://code.sololearn.com/cI5VXLwl8isY/#cpp
It was worth the hour, because I learned some new stuff,
Hope you can learn some stuff too :)
(Ik this isn't exactly what you asked for but it should help)