Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7089773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:57:48+00:00 2026-05-28T07:57:48+00:00

Suppose I have 4 integers. int a = 4; int b = 2; int

  • 0

Suppose I have 4 integers.

int a = 4;
int b = 2;
int c = 4;
int d = 1;

How can I sort these integers from smallest to biggest. The output needs to be something like this: d, b, a, c Most methods of sorting only give me the value of the sorted integer. I need to know the name.

Edit: Well, I’m writing an AI algorithm. I have 4 ints that store direction priority. (If the AI comes into a wall, it chooses the next best direction). So, I need to find the lowest int, and if the AI can’t move that way, I choose the second to lowest etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:57:48+00:00Added an answer on May 28, 2026 at 7:57 am

    Here is an objective-c approach. Unfortunately, you will not have the fun of writing the AI portion, the sorting is built into the libraries already.

    int north = 1, south = 3, east = 2, west =4;
    
      NSDictionary * nDict = [NSDictionary dictionaryWithObjectsAndKeys:@"north", @"name", [NSNumber numberWithInt:north], @"value", nil];
      NSDictionary * sDict = [NSDictionary dictionaryWithObjectsAndKeys:@"south", @"name", [NSNumber numberWithInt:south], @"value", nil];
      NSDictionary * eDict = [NSDictionary dictionaryWithObjectsAndKeys:@"east", @"name", [NSNumber numberWithInt:east], @"value", nil];
      NSDictionary * wDict = [NSDictionary dictionaryWithObjectsAndKeys:@"west", @"name", [NSNumber numberWithInt:west], @"value", nil];
    
    
      NSArray * toBeSorted = [NSArray arrayWithObjects:nDict,sDict,eDict,wDict,nil];
      NSArray * sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"value" ascending:NO]];
      NSArray * sorted = [toBeSorted sortedArrayUsingDescriptors:sortDescriptors];
      NSLog(@"sorted %@", sorted);
    

    Output

    2012-01-23 19:50:21.079 TestEnvironment[19792:207] sorted (
            {
            name = west;
            value = 4;
        },
            {
            name = south;
            value = 3;
        },
            {
            name = east;
            value = 2;
        },
            {
            name = north;
            value = 1;
        }
    )
    

    Now you can check the highest priority by

    NSString * highestPriority = [[sorted objectAtIndex:0] objectForKey:@"name"];
    

    Now you have some classes you can look up (NSArray, NSDictionary, NSSortDescriptor, NSNumber)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a simple multidimensional structure, like this one: somestr<-array(sample.int(2, 120, replace=TRUE), dim=c(4,5,6))
In C++ methods can have optional arguments, like this: void myFunction (int arg1, int
Suppose I have a table of users. Something like: ID integer, USER text, POSITION
I can't figure this interview question. You have an array of integers. You need
i have never tried something like this so i need your help. i have
Suppose that I have an integer variable in a class, and this variable may
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
Suppose I have an ArrayList of String and an ArrayList of int. My ArrayList
Suppose I have a class A with property b Class A { public int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.