Sorting an Array using Python
Sorting an Array
In this program we need to sort the given array in ascending order such that element will be arranged from smallest to largest. We can sort an array using two loops or in-built function in Python. The outer loop will select an element and inner loop allow us to compare and select element with rest of the element.
- Orignal Array: 7 5 4 2 3
- Array after sorting: 2 3 4 5 7
- Declare and intialize an array
- Loop through the array and select an element.
- The inner loop will be used to compare the selected element from the outer loop with rest of the elemnts of the array.
- If any element is less than the selected element then swap the value.
7 5 3 4 2
2 3 4 5 7