Skip to content

Instantly share code, notes, and snippets.

@volkanunal
Created December 26, 2020 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save volkanunal/4be906118be6251487eae883ad15d6ff to your computer and use it in GitHub Desktop.
Save volkanunal/4be906118be6251487eae883ad15d6ff to your computer and use it in GitHub Desktop.
//NOT : SIZE verilen dizideki en yüksek değerden daha yüksek seçilmiştir.
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
const int test_array[SIZE] = {-2, 5, 1, -1, -3, -7, 7, 2, 3, 5};
int main(void) {
int emulate_array[SIZE] = { 0 };
for (int i = 0; i < SIZE; ++i)
{
//Dizide aynı sayının tekrarı olması durumu göz önünde alındı. Örnek dizi de -7 -7 ya da 5 5 gibi aynı ranka sahipse elenir.
if (test_array[i] < 0 && emulate_array[abs(test_array[i])] == 1)
{
printf("\r\n Bulundu = %d", abs(test_array[i]));
}
else if (test_array[i] > 0 && emulate_array[test_array[i]] == -1)
{
printf("\r\n Bulundu = %d", abs(test_array[i]));
}
if (test_array[i] > 0)
{
emulate_array[test_array[i]] = 1;
}
//Negatif sayi dizide daha önce gelebilir.
else
{
emulate_array[abs(test_array[i])] = -1;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment