+ 2

Give me the best way to reverse the elements in the list [1,3,4,7,8,5,6,2,9] without using built-in functions in any language?

16th Mar 2020, 8:59 PM
Sudhakara Bathala
8 Answers
+ 10
Please show us your attempt, so that we can see what you have done so far. So it would be nice, if you could link your code here. Thanks.
16th Mar 2020, 9:02 PM
Lothar
Lothar - avatar
+ 5
#python a = list(range(10)) a = [a.pop() for _ in range(len(a))] Anyway one possible algorithm is make a loop that goes from 0 to half of the list size. Swap the first element with the last. Then swap the second element with the second from the back. And so on. You can use a temp var for swapping.
16th Mar 2020, 9:42 PM
Tibor Santa
Tibor Santa - avatar
+ 4
shouldn't it be without built-ins? 🤔
16th Mar 2020, 9:37 PM
Lothar
Lothar - avatar
16th Mar 2020, 10:25 PM
A͢J
A͢J - avatar
+ 3
Traverse the list backwards and copy each element into a new list.
18th Mar 2020, 8:20 PM
Sonic
Sonic - avatar