I just want to make the input to custom number instead of randomized number ie i want my code to sort this [0,5,1,3,4,2] instead of randomized number, can anyone revise my whole code? Thank you so much
I already try putting and changing the random part but it wont work
https://pastebin.com/xhnEUwf9
note : My code is sorting algorithm that sorts a list of numbers (representing frogs) in descending order. The sorting is done through a series of swaps, and the algorithm counts the number of moves required to achieve the sorted order.
Here's a breakdown of the sorting rule applied in my code:
**Initialization**: A list of
**Sorting**: The
**Swapping Mechanism**:
- The algorithm performs a loop until the sublist of
- It uses two pointers,
- Swaps are made between adjacent elements or by skipping one element if it results in a larger number moving towards its correct position.
- The pointer
**Counting Moves**: Each swap counts as a move, and the total number of moves is recorded in
This algorithm is not a standard sorting algorithm like Bubble Sort, Selection Sort, or Quick Sort. It's a custom algorithm that seems to be designed for a specific problem, possibly a variation of the "frog puzzle" where the goal is to sort the frogs in a particular order with the least number of moves.
Frog sorting program. The task is Prepare a list/place to input frog numbers during the presentation later instead of random number. The frogs at the start are arranged randomly, with the empty/0 spot on the far left.
I already try putting and changing the random part but it wont work
https://pastebin.com/xhnEUwf9
note : My code is sorting algorithm that sorts a list of numbers (representing frogs) in descending order. The sorting is done through a series of swaps, and the algorithm counts the number of moves required to achieve the sorted order.
Here's a breakdown of the sorting rule applied in my code:
**Initialization**: A list of
frogs
is created with random numbers between the lower_bound
and upper_bound
, and a 0
is appended at the beginning. The same list is copied to frogs_sorted
.**Sorting**: The
frogs_sorted
list is sorted in reverse order (descending).**Swapping Mechanism**:
- The algorithm performs a loop until the sublist of
frogs
from index 1 to n
matches the sorted list frogs_sorted
.- It uses two pointers,
p
and q
, to traverse the list from left to right (q == 0
) and right to left (q == 1
).- Swaps are made between adjacent elements or by skipping one element if it results in a larger number moving towards its correct position.
- The pointer
p
is incremented or decremented accordingly, and q
is toggled when the end or the beginning of the list is reached.**Counting Moves**: Each swap counts as a move, and the total number of moves is recorded in
total_moves
.This algorithm is not a standard sorting algorithm like Bubble Sort, Selection Sort, or Quick Sort. It's a custom algorithm that seems to be designed for a specific problem, possibly a variation of the "frog puzzle" where the goal is to sort the frogs in a particular order with the least number of moves.
Frog sorting program. The task is Prepare a list/place to input frog numbers during the presentation later instead of random number. The frogs at the start are arranged randomly, with the empty/0 spot on the far left.