Untitled
Never
#include <stdio.h> // Function to find first occurrence of a given number // in sorted array of integers int findFirstOccurrence(int arr[], int N, int x) { // search space is arr[low..high] int low = 0, high = N - 1; // initialize the result by -1 int result = -1; // iterate till search space contains at-least one element while (low <= high) { // find the mid value in the search space and // compares it with target value int mid = (low + high)/2; // if target is found, update the result and // go on searching towards left (lower indices) if (x == arr[mid]) { result = mid; high = mid - 1; } // if target is less than the mid element, discard right half else if (x < arr[mid]) high = mid - 1; // if target is more than the mid element, discard left half else low = mid + 1; } // return the leftmost index or -1 if the element is not found return result; } // main function int main(void) { int arr[] = {2, 5, 5, 5, 6, 6, 8, 9, 9, 9}; int n = sizeof(arr)/sizeof(arr[0]); int target = 5; int index = findFirstOccurrence(arr, n, target); if (index != -1) printf("First occurrence of element %d is found at index %d", target, index); else printf("Element not found in the array"); return 0; }
Raw Text
-
FIST4K. Curious nymph tries fisting during affair with BF in living room
5 min ago
-
Makers CBD Gummies Reviews
7 min ago
-
Life Boost CBD Gummies - FACTS, SCAM UPDATED PRICE 2024
7 min ago
-
https://www.facebook.com/CerebrozenReviews/
35 min ago
-
Happy holiday, dear ladies!
35 min ago
-
No Deposit Bonus
36 min ago
-
Adult Telegram Channels
37 min ago
-
Fitspresso Reviews – PRICE ALERT (Hoax Or Real) Fitspresso Coffee Loophole Expert In Weight Loss?
39 min ago
-
"ACV Delight: Shark Tank's Gummy Keto Marvel"
51 min ago
-
SMA BERHIJAB CANTIK BGT
52 min ago