Any Java Gurus?

This is a discussion on Any Java Gurus? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Sorry about a java question on a c++ board, but this is the best place I've found to get some ...

  1. #1
    Unregistered
    Guest

    Any Java Gurus?

    Sorry about a java question on a c++ board, but this is the best place I've found to get some answers.

    I'm sure the answer won't be much diifferent anyway. lol

    I am trying to create a 2 dimensional LinkedList . How do I do this??!!!!!!

    Part of my code:

    // list is a linked list. I am trying to add
    // the required amount of queues to it

    for (int w = 0; w < num; w++)
    {
    list.add(new LinkedList());
    }

    // next, I want to add the elements to
    // the first queue and print out the
    // results each time.

    process = new Process (arrive, service, pid);
    list.get(0).add(process);
    finalChange = (Process)list.get(0).get(0);
    System.out.println (finalChange.pid);

    I would have thought that list.get(0) would get me the reference that I needed to access the LinkedList that carries queue #1. The compiler does not seem to like this reference.

    Any ideas?

  2. #2
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    atleats put it under general. only c++prgoraming come to this forum. u would have to get lucky to ifn someone who knows both, if you wont a reply post on general
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  3. #3
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You'll probably get flamed for posting a Java question, and redirected to a Java board somewhere else.

    You need to remember your casts though. get(0) (as an aside, perhaps you should use getFirst() instead of get(0), it's probably faster) returns an Object, not a LinkedList.

    Code:
    process = new Process (arrive, service, pid);
    // list.get(0).add(process); // Object has no add method
    ((LinkedList) list.getFirst()).add(process)
    // finalChange = (Process)list.get(0).get(0); // same problem
    finalChange = (Process) ((LinkedList) list.getFirst()).getFirst()
    System.out.println (finalChange.pid);
    Last edited by SilentStrike; 07-28-2002 at 02:08 AM.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You could probably sneak a java question onto the C# board...although I'm pretty experienced in java and have never been on the C# board.

  5. #5
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    >> I'm pretty experienced in java and have never been on the C# board.

    And did you know that MY best quality is that i'm just so modest ...
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  6. #6
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002
    Posts
    1,198
    Here is a great java forum

    http://forum.java.sun.com/
    -MethodMan-

    Your Move:Life is a game, Play it; Life is a challenge, Meet it; Life is an opportunity, capture it.

    Homepage: http://www.freewebs.com/andy_moog/home.html

  7. #7
    Registered User
    Join Date
    Jul 2002
    Posts
    16
    Thanks for reponding SilentStrike! I thought for sure your idea would have worked cause it made sense. But, alas, it does not. I will try to post in general. Don't want to make C++ gurus mad.

  8. #8
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    What errors does the compiler say?
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I am trying to create a 2 dimensional LinkedList . How do I do this??!!!!!!
    Forget about the language and go back to the data structure. Imagine a 2 x 2 linked matrix, this can be done very easily in any language that supports a linked data structure. There is one big consideration though, if you only want to traverse the list as you would a two dimensional array, like so:
    Code:
    a[0][0]
    a[0][1]
    a[1][0]
    a[1][1]
    Then you probably would be better off with just a simple linked list since the principle is the same, you go through the list in a linear motion. If, however, your goal is to go from say a[0][0] to a[1][0] without having to go through all of the first row then a linked matrix would be appropriate. To make such a matrix, consider the declaration:
    Code:
    // Big time pseudocode, I never use Java :P */
    public class LinkedMatrix
    {
      // Data here
      LinkedMatrix up;
      LinkedMatrix down;
      LinkedMatrix left;
      LinkedMatrix right;
    }
    Instead of just a next link, you have four, one for each direction in the matrix. Building the matrix is of course, more difficult. You have to consider normal traversal from a[0][1] to a[1][0] as well as any non-linear traversal.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C#, Java, C++
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-05-2004, 02:06 PM
  2. First Java Class at college
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 09-29-2004, 10:38 PM
  3. The Java language is being expanded
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 06-11-2004, 09:07 PM
  4. Java woes
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 07-06-2003, 12:37 AM
  5. Visual J#
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 02:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21