Results 1 to 3 of 3
  1. #1
    djbeko06 is offline Member
    Join Date
    Sep 2011
    Rep Power

    Default Search a two Dimensional Array

    How do u sort and search a two dimensional array for a key e.g 4 and return the index of the key maybe 3????

    - -
    | 1 8 0 |
    | 4 8 4 |
    | 2 6 9 |
    - -


  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power

    Default Re: Search a two Dimensional Array

    That's not how this works. What have you tried? Please read the link in my signature on asking questions the smart way.

    How would you do this by hand, without a computer?
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Rep Power

    Default Re: Search a two Dimensional Array

    Sorts and searches are 2 different things. If you want to search the 2d array for a value (assuming it is 'unsorted'), you need to step through each element in the 2d array and determine if it equals the value you are looking for. Let's say this is the array that you are searching:

    Java Code:
    int[][] myArray = new int[y][x];
    //Populate the array with data
    //Now ready to search

    Use the size declarations(y,x) that you made when you allocated the array to help determine your for loop bounds.

    Java Code:
    for(int row=0; row<y; row++){
      for(int col=0; col<x; col++{
    Last edited by sehudson; 09-13-2011 at 05:08 PM.

Similar Threads

  1. Help with Two Dimensional Array
    By johnjacob in forum New To Java
    Replies: 2
    Last Post: 06-03-2011, 08:22 PM
  2. 2 dimensional array
    By sehudson in forum New To Java
    Replies: 5
    Last Post: 02-21-2011, 12:56 AM
  3. 2 dimensional array help!
    By ber1023 in forum New To Java
    Replies: 9
    Last Post: 01-02-2011, 01:29 AM
  4. Two dimensional array
    By niu_niu in forum New To Java
    Replies: 4
    Last Post: 06-13-2010, 12:34 AM
  5. about two dimensional array
    By matin1234 in forum New To Java
    Replies: 2
    Last Post: 06-01-2010, 11:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts