Creating an array of linked lists java -


working on problem discovering how connections between nodes long , short distances apart reduce route 1 node another. im creating array of example [500] want each point in array connected 2 before , 2 follow it. , points in array connected random place. need create adjacency matrix (an array of linked lists) , im terrible linked lists. me setting up, here node class created:

i going use array of arrays [][] figured since points connected more others linked list better suit needs.

edit: yeah guy told me use javas linked list, whill dont understand cycle through array of [500] , create new linked list , set first 2 nodes in linked list positions in array?

thanks guys!

edit:

got sorted out, anyways!

public class smallworld {  public static void main(string [] args){      list<integer>[] sworld = new list [500];      //fill array nodes.     (int = 0; < sworld.length; i++){         sworld [i] = new linkedlist<integer>();          if(i == 0){             sworld[i].add(i + 1);             sworld[i].add(i + 2);                        }         else if( == 1){             sworld[i].add(i - 1);             sworld[i].add(i + 1);             sworld[i].add(i + 2);         }         else if( == sworld.length - 2){             sworld[i].add(i - 2);             sworld[i].add(i - 1);             sworld[i].add(i + 1);         }         else if( == sworld.length - 1){             sworld[i].add(i - 2);             sworld[i].add(i - 1);         }         else{             sworld[i].add(i - 2);             sworld[i].add(i - 1);             sworld[i].add(i + 1);             sworld[i].add(i + 2);         }       } 


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -