An array of lists

A am with a group of students tasked with implimenting an array of linked lists to carry a set of integers (size unknown). We have a skeleton code to work from and will use some sort of hash function to find the cell that contains the list that an integer should be assigned to. There are two classes, the first is for the array and the hashing function and the second is the List class. We will be using a singly linked list and the integers will be kept in sorted order.
If for instance we are looking at the delete methods would something like the Following, inserted in the array class methods, Call upon the "List" class delete method for that particular array cell?
public void delete(int n) {
for OurListArray[ (some hash function) ] //my code
List.delete(n); //my code
If this was correct then I'd expect adding and finding and integer to be similar.
Does this make any sense?
Give me a clue so that I can try and proceed.

OK, this sounds similar to the kind of thing you might do for a Radix sort, or similar (which I don't know how to do off hand). But I can give you some clues about implementing a singly linked list.
Your List class, or interface will provide methods for adding, deleting, or traversing to a particular int. Somewhere you will probably want an additional class providing the concept of a List Node, encapsulating the value (int) and a pointer to the next Node in the list.
For example:
public class LinkedList {
     private Node head = null;
     private Node tail = head;
     public void addLast(int data) {
          tail.next = new Node(data, null);
          tail = tail.next;
     public void addFirst(int data) {
          head = new Node(data, head);
     // And so on...
     class Node {
          int data;
          Node next;
          public Node(int data, Node next) {
               this.data = data;
               this.next = next;
}You will probably want to put in delete / remove mechanisms as well, but remember that if you delete a node, you must handle the pointer in the preceding node, or you'll magically get it back whenever you traverse the list.
Traversal mechanisms would be best put in an Iterator, but this is not a trivial structure, so perhaps you could implement this simply by maintaining a cursor on the Node you are looking at.
Essentially, you need to be able to play with references easily - almost as if they are pointers in another language.
To summarise, you have a contolling List Implementation that hides the underlying Nodes to the user. You accomplish Node insertion and deletion by playing with the Node references, but all the user sees is ints.
I'm not sure if this helps any...

Similar Messages

  • Storing sql recordset in an array, or list, or similar

    I should probably understand hashmaps better before posting this, but if someone could point me in the right direction, I'd appreciated it.
    I'd like to store a sql resultset having an integer and a string in an array, or list, or similar. That is, I'd like to close the recordset and still have the data stored somehow.
    Problem wth an array is, as I understand it, even a multi-dimensional array has to be of the same type:
    String [][] records ...or
    int [][] records;
    I'd like to declare:
    int[]String[] records;
    ...and store the resultset into this array(list, or collection, or whatever) in a while loop.
    ResultSet rs = statement.executeQuery();
    int i = 0;
    while ( rs.next() ) {
    records[0] = rs.getString( "ObjectId") ;
    records[i][1] = rs.getString( "ObjectName" );
    rs.close();
    statement.close();
    Any ideas appreciated.
    Amboss

    You could declare create a your own class as -
    class MyRecord extends Object {
    int id;
    String name;
    public MyRecord(int id, String name) {
    this.id = id;
    this.name = name;
    }Then use a Vector to save the records as you iterate
    over the ResultSet
    Vector records = new Vector();
    ResultSet rs = statement.executeQuery(sql);
    while (rs.next()) {
    records.add(
    new
    MyRecord(rs.getInt("ObjectId"),rs.getString("ObjectNam
    e"));
    }To retrieve records you must use the get() method of
    Vector.
    MyRecord rec = (MyRecord)records.get(i);
    Aren't you going to put parameter to Vector<?> ?
    this is based on the JDK Generics 1.5

  • Using Arrays.asList: Is Array[x] == List.get(x)

    I have an Object[] Array and I wish to remove index 'x' from that Object[] Array. If I use Arrays.asList() passing in the existing Object[] Array I will get new List Object containing the objects from the Object[] Array. Is it guaranteed that index 'x' from the Object[] Array is the same Object from the index 'x' in the new List?
    Object[] obj = new String[] {"obj_0", "obj_1", "obj_2", "obj_3"};
    List list = Arrays.asList(obj);
    assertTrue(obj[0] == list.get(0));
    assertTrue(obj[1] == list.get(1));
    assertTrue(obj[2] == list.get(2));
    assertTrue(obj[3] == list.get(3));Are the above assertions always guaranteed to be true?

    Jared_java_dev wrote:
    I thought the JavaDoc API would state it as well. I did originally check that.
    I agree that it should keep the order but I wanted to verify this behavior. It would make some coding logic much more simple.
    Objective is to remove ojb[2]
    String[] obj = new String[] {"obj_0", "obj_1", "obj_2", "obj_
    //Perferred logic
    List<String> list = Arrays.asList(obj);
    //remove unwanted element
    list.remove(2);
    //create new Object[] without unwanted element
    obj = (String[]) list.toArray();
    {code}
    as opposed to
    {code}
    String[] obj = new String[] {"obj_0", "obj_1", "obj_2", "obj_
    //unwanted logic
    List<String> list = Arrays.asList(obj);
    for (int x = 0; x < obj.length; x++) {
    // == or String.equals
    if (list.get(x) == (obj[x])) {
            list.remove(x);
    obj = (String[]) list.toArray();I guess that I could write a sample program and run to verify this .
    Thanks for everyone's input.No, you won't be able to simply 'delete' items from this array-backed list. It is a fixed size list, so additions/deletions are expected to throw exceptions.
    So now my question is: Why is the master an array in the first place? Seems like it should be a List from the get-go.

  • Using an 9 by 9 Array of Lists

    I am currently programming a suduko puzzle and am using a 9 by 9 array of lists to do this.
    List[][] A;                          
    A = new List[9][9];this creates a 9 by 9 array of lists but when i use:
    List A[x][y] = new List[A.add(ob1)][A.add(ob1)];I get an error. Does anyone now how to correctly add numbers to the lists that i have just created.
    Help is much appreciated

    I get an error. Only one? Oh well, I guess you scared the poor compiler to death with that piece of code. If you have any pity at all for your compiler, read the array tutorial:
    http://java.sun.com/docs/books/tutorial/java/data/arraybasics.html
    and then the list tutorial:
    http://java.sun.com/docs/books/tutorial/collections/interfaces/list.html
    If you really need an array of lists, that is...

  • Accessing arrays within lists

    Hi,
    I have a linked list with arrays of type byte stored in. I have managed to access each individual array using list.get(i) but how can I access an individual element of a specific array in the list?
    Thanks and regards,
    Krt_Malta

    void f(List<byte[]> list) {
        byte me = list.get(0)[17];
    }

  • How to restore this kinda XML into an array or list?

    I have a XML file like this
    [msgboard]
    [message]
    [subject] subject [/subject]
    [body] text body [/body]
    [followups]
        [message]
            [subject] subject [/subject]
            [body] text body [/body]
            [followups]
                       [message] ...
            [/followups]
        [/message]
    [followups]
    [/message]
    [/msgboard]so the XML can be unlimited deap.
    I want to read it into an array or list or something like that, so I can use the data.. but how should I store them? any ideas ? thanks

    Please refrain from cross posting http://forum.java.sun.com/thread.jspa?threadID=785000

  • Converting Arrays to List

    Hi,
    I have the following function that converts String[] to List of int and it's working
    private String putSelect(){
            String msg = SUCCESS;
            try{
                if (session.get("selectCat") != null){               
                    String[] aux = (String[])session.get("selectCat");
                    List aux2 = new ArrayList();
                    for (int i=0;i<aux.length;i++){
                      aux2.add(Integer.parseInt(""+aux));
    setSelectCat(aux2);
    }catch (Exception e) {       
    msg = ERROR;
    System.out.println(e.getMessage());
    return msg;
    but I know that is possible to convert from array to list using :
    Array.asList
    but I need that the resulting list be of int not String, is there a way to modify this setSelectCat(Arrays.asList((String[])session.get("selectCat"))); in order for that to be possible?
    thanks, V

    if you're using java 1.5, then a better loop might be:
    for (String num : aux) {
       aux2.add(Integer.parseInt(num));
    }The variable aux is already a String, so doing "" + aux is pointless. I don't know if a compiler would clean that up for you or not. I'm told that a 'for / in' loop as coded above is marginally faster than an incrementor loop.
    Enjoy!

  • How to work with Arrays (or Lists) in WebService responses?

    Good Evening!
    In a BPEL process I invoked a some Webservice which return me a list of persons. Like this:
    <response>
    <personList>
    <person>Person1</person>
    <person>Person2</person>
    <person>Person3</person>
    </persons>
    </respons>
    Now i need to do something with Every returned element (like to invoke another webservice with parameter "person" (so i need to invoke a webservice for a 3 times))
    How i can do this?
    In Assign element CopyRules i see only:
    response |_
    personList|_
    person
    Like a person is a simple element, not a list.
    Should i use a For Each Element? And what to do next?
    Thank you.

    http://download.oracle.com/docs/cd/E12483_01/integrate.1013/b28981/manipdoc.htm#BABCHBFB
    http://clemensblog.blogspot.com/2006/03/bpel-looping-over-arrays-collections.html
    http://oraclebpelindepth.blogspot.com/2008/09/arrays-in-bpel_21.html
    you indeed need for each and loop over every person element in
    in the loop you can do the invokes of the other service with the input-data of the corresponding person-element-data
    person[1]/name
    person[2]/name
    etc

  • Arrays to lists in db or something better?

    I have a form that is dynamic in that it first asks the user
    how many entries they will be making. If the user says 5, an array
    is created to accomodate that such as
    <cfset SESSION.newarray = structNew(2)>
    The form is generated using a cfloop to create the rows in
    accordance with the number of entries requested.
    I don't want to put these values into a list and into the
    database, but the user can request up to 20 rows. In this case the
    user is asked how many new customers he wishes to add to the
    database, then the next page creates the array, loops through the
    <cfinput> lines and creates the table. THe results of the
    form is then stored into session variables, so that the user can go
    back and forth through the forms without losing data, and not
    requiring a database read/write each time, until the end. THen the
    data from the array is fed into the database for storage.
    My question (finally!) is this: Is it more effecient to
    create 20 columns in the database to store each of the possible
    entries, or create a list and store the data in lists, pulling the
    lists out and finding data from the lists or is there a better way?
    Thanks.

    A better way would be to store 20 records. Sounds like a
    course in data modelling would benefit you.

  • Arrays to List component

    I am fairly new AS3 coder now using Flash Builder and I can't work out how to display my data (a collection of actionscript arrays returned by a AS3 function) in a List component as a list of labels and images. My arrays look like this:
    var aNames:Array = new Array("John", "Ringo", "Paul");
    var aImages:Array = new Array("http://myserver.com/image1.jpg", "http://myserver.com/image2.jpg", "http://myserver.com/image3.jpg");
    Now I want to display them in a list component, each list item has the image on the left and then the name on the right.
    Can anyone provide an example please, I think I need to use an arraycollection and a custom item renderer inside the list and then have the lists dataprovider set to the arraycollection but have not been able to construct the code.
    Many thanks.

    You'll get better responses on the Flex general discussion forum for non-Flash Builder queries.
    -Anirudh

  • How can fill javascript array from list in jsf backing bean

    Hello
    i have an array in javascript and i want to fill in from the list which is coming from the backing bean how can i do that.
    Regards

    Hi,
    using the ExtendedRenderkitService class you can send JavaScript calls from a managed bean to the client. So in your case you call a client side javaScript method and pass the array information as an argument. The way you pass the array data is up to you. You may just pass a character delimited list, or use JSON object notation in case the list shows objects. Note that this is for JDeveloper 11.In 10.1.3 there is no server side JavaScript API. Here you would have to add the JavaScript to the page when rendering it.
    Frank

  • Array into list

    I was wondering, if it is possible to pass Director
    Javascript array object to Director linear list?
    Are there any array search functions in Director Javascript
    similar to: getOne, findPos etc.?
    TIA
    Yochai Gani

    Thanks Sean
    That was what I suspected of. Still, Javascript documentation
    is so faint and vague I have hoped there are some undocumented
    commands or features.
    In a project I’m doing I’m reading a text file,
    transform it into a list (array) and find a value in it (Locating
    streets by city name).
    Since I am a big fan of short and neat code, if I could just
    combine lingo and Javascript I could make the entire operation with
    3 lines of code without using any loop!
    This could be done by using “split” and
    “getOne”.
    Still, it’s a pity, it would be really nice if it could
    work.
    Yochai Gani

  • Setting array as list of cgi.script_name

    This should be a gimme, but I'm stumped. Check out this code.
    The final dump shows an empty array, what am I missing?
    Script name:
    <cfoutput>#cgi.SCRIPT_NAME#</cfoutput><BR>
    <cfset myList = cgi.scipt_name>
    <cfset myArray = arrayNew(1)>
    <cfloop list="#mylist#" delimiters="/" index="i">
    <cfset myArray = arrayAppend(myArray, i)>
    </cfloop>
    <cfdump var="#myArray#">

    1) a typo:
    <cfset myList = cgi.script_name>
    2) if you use both delimiters \ and /, you will not have to
    worry which one is required:
    <cfloop list="#mylist#" delimiters="\/" index="i">
    3)
    ArrayAppend() returns a boolean. You usually don't need to
    set it to anything, certainly not to an array:
    <cfset arrayAppend(myArray, i)>

  • Arrays of arrays or list of arrays?

    Hi!
    I've spent 2+ hours now trying to figure this out/browsing the web.
    I have x number of rows in db, and now I'm trying to convert this data to an array.
    Like this:
    String foo[] = null;
    Array unordered[];
    int i=0;       
    while(ResultSet.next()){
       foo = new String[]{  ResultSet.getString("osa_id"),
                            ResultSet.getString("k_teksti"),
                            ResultSet.getString("linkki"),
                            ResultSet.getString("taso"),
                            ResultSet.getString("k_alaisuus")};
       unordered[i] = valiaikainen;
       i++;
    }Compiles, but gives errors during run. In PHP this is annoyingly easy. (Grin.) Also I have to manipulate the order of the unordered, depending the data that arrays it contain holds. Is there easier way? Any help welcome, as I'm out of ideas.
    Thanks
    -9902468

    OOps. Stopid question.
    Figured it out right after posting the question...
    Well newbies are newbies, eh?
    -9902468

  • How to get select items from multi select in an array or list in jsp

    i have the following multi select which is basically an array coming from the database how can select couple of them and put them in an array in jsp and then save them in the session so when i click the next button they continue till i reach the last finish button of my wizard:
    <SELECT MULTIPLE SIZE=5>
    <OPTION VALUE="o1">Option 1
    <OPTION VALUE="o2">Option 2
    <OPTION VALUE="o3">Option 3
    <OPTION VALUE="o4">Option 4
    <OPTION VALUE="o5">Option 5
    <OPTION VALUE="o6">Option 6
    </SELECT>
    Option 1Option 2Option 3Option 4Option 5Option 6

    Hi,
    As you are tracking changes in ALV data you must define a event handler for ALV evenr ONDATA_CHECK.
    On defining an event handler you will be getting a structure called t_param.
    It contains an element called t_deleted rows.
    See this code to have an idea.
    method ONDATACHECK .
      DATA: x_delete_row LIKE LINE OF r_param->t_deleted_rows.
      "      i_addr_factr TYPE STANDARD TABLE OF ycot_addr_factr,
       "     x_addr_factr LIKE LINE OF i_addr_factr.
    TYPES t_proj_constr TYPE ycot_proj_constr.
      FIELD-SYMBOLS: <fs_row> TYPE t_proj_constr.
      IF wd_comp_controller->ya_optyp = 'DELETE'.
        LOOP AT r_param->t_deleted_rows INTO x_delete_row.
          "x_addr_factr ?= x_delete_row-r_value.
          ASSIGN x_delete_row-r_value->* TO <fs_row>.
        DELETE FROM ycot_proj_constr  WHERE plant = <fs_row>-plant
                                     AND   yr_nbr = <fs_row>-yr_nbr
                                     AND   period = <fs_row>-period
                                     AND  billback_pr_fmly = <fs_row>-billback_pr_fmly
                                     AND  prd_nm = <fs_row>-prd_nm.
      ENDLOOP.
    I hope it helps.
    Regards,
    Sumit Oberoi

Maybe you are looking for

  • Rebate Aggrements

    Hi gurus, when i saved billing document it is saying error in account determination. When we are posting to G/L account which G/l account i have to post (What is the name-description)

  • Linking to a specific frame from JSP page

    I am trying to link to site that has frames. I want to load a specific jsp in frame 3. Does anyone know how to pass the target and source values? I have been looking for tutorials unsuccessfully.

  • Query to select value for max date from a varchar field containing year and month

    I'm having trouble selecting a value from a table that contain a varchar column in YYYY-MM format.  ex. Emp_id Date Cost 10264 2013-01 5.00 33644 2013-12 84.00 10264 2013-02 12.00 33644 2012-01 680.0 59842 2014-05 57.00 In the sample data above, I wo

  • XML syntax to revoke all the AccessControlEntry

    Hi all!!! I would like to know if there is an XML syntax to revoke all the AccessControlEntry of an ACL Thanks

  • Livecycle - Active Directory

    I need display a control depending of the user logged in the SO exists on a active directory specific group. Is it possible? The form is design in Adobe LiveCycle ES4, THANKS