“Defle Linearearch (Array, N, K):” Code-Antworten

Defle Linearearch (Array, N, K):

def LinearSearch(array, n, k):

    for j in range(0, n):

        if (array[j] == k):

            return j

    return -1

 
array = [1, 3, 5, 7, 9]

k = 7
n = len(array)

result = LinearSearch(array, n, k)

if(result == -1):

    print("Element not found")

else:

    print("Element found at index: ", result)
cs181040 KFUEIT

Defle Linearearch (Array, N, K):

def LinearSearch(array, n, k):

    for j in range(0, n):

        if (array[j] == k):

            return j

    return -1

 
array = [1, 3, 5, 7, 9]

k = 7
n = len(array)

result = LinearSearch(array, n, k)

if(result == -1):

    print("Element not found")

else:

    print("Element found at index: ", result)
cs181040 KFUEIT

Ähnliche Antworten wie “Defle Linearearch (Array, N, K):”

Fragen ähnlich wie “Defle Linearearch (Array, N, K):”

Weitere verwandte Antworten zu “Defle Linearearch (Array, N, K):” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen