doubly linked list someone fix it plz

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: doubly linked list someone fix it plz

  1. #1
    Join Date
    May 2004

    doubly linked list someone fix it plz

    Hello gents .. and ladies
    Here's my problem for today

    the following prg must print the id and address of each node that i create. only prb is that it wont work. it will only print twice where both addresses are the same. should be diff. i should get a TOP, NODE 1, NODE 2, ETC, BACK am to print the adds of each of them

    import javax.swing.*;

    class employee{

    String id;

    employee next;
    employee back;

    class doublylinkedlist{
    public static void main (String args[])
    String idask;

    employee top = new employee();
    employee BBack = new employee();

    employee temp1 = new employee();
    employee temp2 = new employee();
    employee temp3 = new employee();

    int i = 0;
    int j;

    int size = Integer.parseInt(JOptionPane.showInputDialog("How many records would you like to create?"));

    for (; i < size; i++)
    idask = JOptionPane.showInputDialog("enter rec num");

    if (i == 0)
    { = idask; = temp1;
    temp1.back = top; = BBack;
    BBack.back = temp1;
    System.out.println("Top is " + top + "\nNode " + (i + 1) + " = " + temp1);

    { = idask; // this is your new node. node2!
    temp2 = top;

    while ( != BBack)
    temp2 =; = BBack;
    temp1.back = BBack.back; = temp1; = temp1;
    System.out.println("Node " + (i + 1) + " = " + temp1);

    many thanx

  2. #2
    Join Date
    May 2004
    If all you have is a main method, then it isn't really a list at all You should capitalize the first letter of each word in your class names, also. I can't really tell you what your problem is, since you aren't really making a linked list at all, and it's just....
    * ^

  3. #3
    Join Date
    May 2004
    lol very well
    i checked it once again and my mistake was that i never initialized my temps inside the for loop. nywyz, am only using temp1 and it has been initialized inside the loop. all is well now. I dont know much about the proper syntax or way of writing a linked list. but i do know that what am writing is a linked list

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center