Raised This Month: $32 Target: $400
 8% 

Find unique entries in array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xice1337
AlliedModders Donor
Join Date: Dec 2015
Old 05-23-2022 , 12:05   Find unique entries in array
Reply With Quote #1

Hey, whats the best way to find all unique entries in an array?
Is there maybe a function thats suitable for this?

Thanks in advance
xice1337 is offline
Cruze
Veteran Member
Join Date: May 2017
Old 05-24-2022 , 11:22   Re: Find unique entries in array
Reply With Quote #2

Took this as a challenge and made this out! Not sure if this is the best way or not. Untested.
PHP Code:
int[] GetUniqueIndexesFromIntegerArray(int[] array, int maxsize)
{
    
int count 0;
    
int[] indexes = new int[maxsize+1];
    for(
int i 0maxsizei++)
    {
        for(
int j 0maxsizej++)
        {
            if(
== j)
            {
                if(
== maxsize-1)
                {
                    
indexes[count++] = i;
                    break;
                }
                continue;
            }
            else if(array[
i] == array[j])
            {
                break;
            }
            else if(
== maxsize-1)
            {
                
indexes[count++] = i;
            }
        }
    }
    return 
indexes;
}

int[] GetUniqueIndexesFromStringArray(char[][] stringsint maxsize)
{
    
int count 0;
    
int[] indexes = new int[maxsize+1];
    for(
int i 0maxsizei++)
    {
        for(
int j 0maxsizej++)
        {
            if(
== j)
            {
                if(
== maxsize-1)
                {
                    
indexes[count++] = i;
                    break;
                }
                continue;
            }
            else if(
strcmp(strings[i], strings[j]) == 0// case sensitive.
            
{
                break;
            }
            else if(
== maxsize-1)
            {
                
indexes[count++] = i;
            }
        }
    }
    return 
indexes;

__________________
Taking paid private requests! Contact me
Cruze is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode