Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The method to sort an array while keeping the original array unchanged is to create a copy of the original array and then sort the copy. This can be done using any sorting algorithm of your choice. The original array remains unchanged while the sorted copy can be used for further processing. Here is an example code snippet in Python:

# Original array
arr = [3, 1, 4, 2, 5]

# Create a copy of the original array
sorted_arr = arr.copy()

# Sort the copy using any sorting algorithm
sorted_arr.sort()

# Print both arrays
print("Original array:", arr)
print("Sorted array:", sorted_arr)

Output:

Original array: [3, 1, 4, 2, 5]
Sorted array: [1, 2, 3, 4, 5]