Untitled

mail@pastecode.io avatar
unknown
python
6 months ago
1.1 kB
1
Indexable
Never
def LShift(Arr, n):
    n = n % len(Arr)
    Arr[:] = Arr[n:] + Arr[:n]

def RShift(Arr, n):
    n = n % len(Arr)
    Arr[:] = Arr[-n:] + Arr[:-n]

def find_median(Arr):
    sorted_arr = sorted(Arr)
    length = len(sorted_arr)
    if length % 2 == 0:
        return (sorted_arr[length // 2 - 1] + sorted_arr[length // 2]) / 2
    else:
        return sorted_arr[length // 2]

def reverse_in_place(Arr):
    start, end = 0, len(Arr) - 1
    while start < end:
        Arr[start], Arr[end] = Arr[end], Arr[start]
        start += 1
        end -= 1

def search_element(Arr, element):
    for i, value in enumerate(Arr):
        if value == element:
            return f"Element {element} found at position {i}."
    return "Element not found."

# Sample Usage
Arr = [10, 20, 30, 40, 12, 11]
n = 2
LShift(Arr, n)
print("Left Shift:", Arr)

Arr = [10, 20, 30, 40, 12, 11]
n = 2
RShift(Arr, n)
print("Right Shift:", Arr)

Arr = [10, 20, 30, 40, 12, 11]
print("Median:", find_median(Arr))

Arr = [10, 20, 30, 40, 12, 11]
reverse_in_place(Arr)
print("Reversed List:", Arr)

element_to_search = 30
print(search_element(Arr, element_to_search))
Leave a Comment