Linked List trouble

//I need to add a header node into this Linked list class and
// i dont understand it. can anyone give me a few pointers.
// This is the orginal code. What im trying to figure out is below.
public abstract class LinkedList implements ListInterface
protected class ListNode
// Used to hold references tolist nodes for the linked list implementation
protected Listable info; // the info in a list node
protected ListNode next; // a link to the next node on the list
protected ListNode list; // reference to the first node on the list
protected int numItems; // Number of elements in the list
protected ListNode currentPos; // Current position for iteration
public LinkedList()
// Creates an empty list object.
numItems = 0;
list = null;
currentPos = null;
public boolean isFull()
// Determines whether this list is full.
return false;
public int lengthIs()
// Determines the number of elements on this list.
return numItems;
public abstract boolean isThere (Listable item);
// Determines if element matching item is on this list.
public Listable retrieve (Listable item)
// Returns a copy of the list element with the same key as item.
ListNode location = list;
boolean found = false;
while (!found)
if (item.compareTo(location.info) == 0) // if they match
found = true;
else
location = location.next;
return location.info.copy();
public abstract void insert (Listable item);
// Adds a copy of item to this list.
public void delete (Listable item)
// Deletes the element of this list whose key matches item�s key.
ListNode location = list;
// Locate node to be deleted.
if (item.compareTo(location.info) == 0)
list = list.next; // Delete first node.
else
while (item.compareTo(location.next.info) != 0)
location = location.next;
// Delete node at location.next.
location.next = location.next.next;
numItems--;
public void reset()
// Initializes current position for an iteration through this list.
currentPos = list;
public Listable getNextItem ()
// Returns copy of the next element in list.
Listable nextItemInfo = currentPos.info.copy();
if (currentPos.next == null)
currentPos = list;
else
currentPos = currentPos.next;
return nextItemInfo;
//now heres the part i dont get i need to make list point to a new
// node say HeaderNode. Now wouldnt just...
public LinkedList()
// Creates an empty list object.
numItems = 0;
list.next = HeaderNode; //....this line do the trick???
currentPos = null;
I know that i cant use any insert methods to put it in, so what else could i possibly do?

bump

Similar Messages

  • Linked list troubles

    How do i put a headernode into this constructor?
    protected class ListNode
    // Used to hold references tolist nodes for the linked list implementation
    protected Listable info; // the info in a list node
    protected ListNode next; // a link to the next node on the list
    protected ListNode list; // reference to the first node on the list
    protected int numItems; // Number of elements in the list
    protected ListNode currentPos; // Current position for iteration
    public LinkedList()
    // Creates an empty list object.
    numItems = 0;
    list = null;
    currentPos = null;

    You mean...
    public LinkedList(ListNode nodeHeader)
      numItems = 0;
      list = nodeHeader;
      currentPos = null;

  • Trouble importing third party classes & using linked list in j2me

    Hi!
    I need to use the linked list data structure in a j2me application im developing. Al long as I know, it is not included in standard libraries.
    I found the "workaround", the substitution in Jade Laepaddon. This is actually a set of classes in a directory.
    I know this is extremely dumb, but I have no luck impotring these classes in my project.
    Im using the WTK2.0 to compile and execute the application, but I don't have an Idea how to add a directory in the CLASSPATH.
    So, the actual question should be: how to include a directory of files, so that it can be imported with:
    import dirName.*;
    Thanks!

    Tha import problem is solved, but I'm still not able to use the LinkedList class. In the jade/util/leap there is a LinkedList.java file, but I get an error :
    /home/mile/WTK2.0/apps/myGame/tmplib/jade.jar(jade/util/leap/LinkedList.java):48: class LinkedList is public, should be declared in a file named LinkedList.java
    (source unavailable)
    /home/mile/WTK2.0/apps/myGame/tmplib/jade.jar(jade/util/leap/LinkedList.java):48: cannot resolve symbol
    symbol : class List
    location: class jade.util.leap.LinkedList
    (source unavailable)
    /home/mile/WTK2.0/apps/myGame/tmplib/jade.jar(jade/util/leap/LinkedList.java):48: cannot resolve symbol
    symbol : class Serializable
    location: class jade.util.leap.LinkedList
    (source unavailable)
    /home/mile/WTK2.0/apps/myGame/tmplib/jade.jar(jade/util/leap/Iterator.java):41: class Iterator is public, should be declared in a file named Iterator.java
    (source unavailable)
    when initialising an LinkedList type object.

  • Having trouble with Linked Lists

    I'm making a JApplet with buttons from a Linked List, and the buttons should be unique but they're all returning the same icon and string. Also my refreshImages method and deleteStudents method aren't working except for the very last button. This seems like it's just because of how Linked Lists operate, but I can't wrap my head around it.
    public class FacebookApplet extends JApplet implements ActionListener{
         private Scanner input;
         protected RefSortedList studentsList;
         protected RefUnsortedList buttonList;
         Student studentVar;
         private JButton b, refreshButton, deleteButton;
         private JPanel buttonPanel, etcPanel;
          * Calls:     readStudentNames, setUpImages
         public void init(){
              readStudentNames();
              setUpImages();
              setLayout(new BorderLayout());
              setSize(500,670);
              etcPanel = new JPanel(new BorderLayout());
              refreshButton = new JButton("Refresh");
              deleteButton = new JButton("Delete");
              buttonList.reset();
              etcPanel.add("West", refreshButton);
              etcPanel.add("East", deleteButton);
              add("North", buttonPanel);
              add("South", etcPanel);
              refreshButton.addActionListener(this);
              deleteButton.addActionListener(this);
          * Pre:          students.dat in current directory
          *                studentList instantiated
          * Post:     studentList has Student objects with names, not images(yet)
          * Purpose:     to set up studentList with student names
         private void readStudentNames(){
              try {
                   FileReader dataInput = new FileReader("students.dat");
                   input = new Scanner(dataInput);
              } catch (FileNotFoundException e) {
                   System.err.println("ERROR:Students.dat file not found");
                   e.printStackTrace();
              studentsList = new RefSortedList();
              while(input.hasNextLine()){
                   String studentName = input.nextLine();
                  studentVar = new Student(studentName);
                   studentsList.add(studentVar);
              System.out.println(studentsList + "");
         }//readStudentNames()
          * Pre:          studentList set up with names
          *                .jpg files are in current directory
          * Post:     buttons set up with images in buttonList and buttonPanel
          * Purpose:     to set up buttons with Student names and images
         private void setUpImages(){
              ImageIcon studentPic;
              Student studentStringPic;
              studentsList.reset();
              buttonList =  new RefUnsortedList();
              buttonPanel = new JPanel(new GridLayout(5,3));
              for (int k = 0; k < studentsList.size(); k++) {
                   studentPic = new ImageIcon(studentVar.toString() + ".jpg");
                   studentStringPic = new Student(studentVar.toString(), studentPic);
                   b = new JButton(studentStringPic.toString(), studentStringPic.getIcon());
                   b.setVerticalTextPosition(AbstractButton.BOTTOM);
                  b.setHorizontalTextPosition(AbstractButton.CENTER);
                   b.addActionListener(this);
                   buttonList.add(b);
                  buttonPanel.add(b);
                   studentsList.getNext();
          * Pre:          buttonList set up
          * Post:     All buttons enabled
          * Purpose:     To enable all buttons in buttonList
         public void refreshImages(){
              for(int i=0;i<buttonList.size();i++){
                   b.setEnabled(true);
                   buttonList.getNext();
         * Pre:     buttonPanel, buttonList set up
         * Post:    disabled buttons removed from buttonPanel
         * Purpose: To delete those students whose buttons are disabled
        private void deleteStudents(){
             for(int k=0; k<buttonList.size();k++){
                  if(!b.isEnabled())
                       buttonPanel.remove(b);
                  buttonList.getNext();
             this.repaint();
         public void actionPerformed(ActionEvent e) {
              JButton b = (JButton) e.getSource();
              if(e.getSource() == deleteButton){
                   deleteStudents();
              else if(e.getSource() == refreshButton){
                   refreshImages();
              else{
                   b.setEnabled(false);
    }Student Class:
    public class Student implements Comparable{
         private String name;
         private Icon icon;
         public Student(String nameT){
              name = nameT;
         public Student(String nameT, Icon iconT){
              name = nameT;
              icon = iconT;
         public int compareTo(Object arg0) {
              if(this.equals(name))
                   return 1;
              else
                   return -1;
         }//compareTo()
         public boolean equals(){
              boolean equalTo = false;
              if(this.equals(name))
                   equalTo = true;
              return equalTo;
         }//equals()
          * Pre: LL is instantiated and filled
          * Post: none
          * Purpose: return the name of the student
         public String toString(){
              return name;
         }//toString()
         public Icon getIcon(){
              return icon;
    }

    I fixed the other things, I just need to fix two more problems and then clean up my code so it looks more professional.
    First problem: When I add the Student variables to the studentsList, they aren't sorted. I think this is because they aren't being read as Strings and so there's no way to compare them. I could just do studentVar.toString(), but then studentsList would be full of Strings and not Students. Any ideas?
          * Pre:          students.dat in current directory
          *                studentList instantiated
          * Post:     studentList has Student objects with names, not images(yet)
          * Purpose:     to set up studentList with student names
         private void readStudentNames(){
              try {
                   FileReader dataInput = new FileReader("students.dat");
                   input = new Scanner(dataInput);
              } catch (FileNotFoundException e) {
                   System.err.println("ERROR:Students.dat file not found");
                   e.printStackTrace();
              studentsList = new RefSortedList();
              while(input.hasNextLine()){
                   String studentName = input.nextLine();
                  studentVar = new Student(studentName);
                   studentsList.add(studentVar);
              System.out.println(studentsList + "");
         }//readStudentNames()Here's the add() method of RefSortedList:
    public void add(Comparable element)
      // Adds element to this list.
        LLObjectNode prevLoc;     // trailing reference
        LLObjectNode location;    // traveling reference
        Comparable listElement;   // current list element being compared     
        boolean moreToSearch;            
        // Set up search for insertion point.
        location = list;
        prevLoc = null;
        moreToSearch = (location != null);
        // Find insertion point.
        while (moreToSearch)
          listElement = (Comparable)location.getInfo();
          if (listElement.compareTo(element) < 0)  // list element < add element
             prevLoc = location;
             location = location.getLink();
             moreToSearch = (location != null);   // stop looking at end of list
          else
            moreToSearch = false;     // list element >= add element
        // Prepare node for insertion.
        LLObjectNode newNode = new LLObjectNode(element);
        // Insert node into list.
        if (prevLoc == null)        
          // Insert as first node.
          newNode.setLink(list);
          list = newNode;
        else
          // Insert elsewhere.
          newNode.setLink(location);
          prevLoc.setLink(newNode);
        numElements++;
      }

  • Changing data in a linked list object.

    hi,
    i'm still pretty new to java, so bear with me if i am making stupid mistakes, heh.
    i'm having trouble with changing data in an object stored in a singly-linked list. i've created a class that will store polynomials in sorted order (descending) in a singly-linked list. each linked list is one polynomial, and each node references to a polynomial object that stores two ints: the coefficient and the exponent of that term.
    i'm having trouble when it comes to 'collecting like terms,' though. here's a rough skeleton of my code:
    public class Polynomial
    private LinkedList polynoList;
    private LinkedListItr Itr;
    private int coeff;
    private int exponent;
    public Polynomial()
    zeroPolynomial();
    } // this constructor sets up an empty linked list
    public Polynomial( int c, int e )
    coeff = c;
    exponent = e;
    } // this creates a Polynomial object storing the two ints
    public void zeroPolynomial()
    polynoList = new LinkedList();
    theItr = polynoList.zeroth();
    } // this method creates the empty linked list and sets the
    //iterator on the zeroth node.
    //various other methods are here, not relevant to my post
    //this next method is the one i am having trouble with.
    //it takes two ints as parameters, the coefficient
    //and the exponent.
    public void insertTerm( int c, int e )
    //...i have a few if/then statements here
    //so that the terms can be inserted in descending order.
    LinkedListItr tester = polynoList.first();
    //the 'tester' iterator is set on the first node
    //this following if statement retrieves the exponent
    //in the current node by casting the information
    //retrieved from the LinkedList retrieve() method
    //into Polynomial, then compares it to the current
    //exponent. if they are equal, i want to add the
    //coefficients.
    if( e == ((Polynomial)tester.retrieve()).getExp() )
    this.coeff = ((Polynomial)tester.retrieve()).getCoeff() + c;
    //a main method goes here wherein the user can insert
    //terms, print the polynomial, etc.
    }//end Polynomial class
    can anyone help me out? the code i'm using compiles correctly, but it does not change the value of the current coeff variable as i'd like to think it should. any input would be GREATLY appreciated, thanks!

    hey,
    thanks for the reply...
    i am sure that ((Polynomial)tester.retrieve()).getExp() will return an int equal to 'e.' i tried this:
    System.out.println("e="+e);
    System.out.println((Polynomial)tester.retrieve()).getExp());
    if( e == ((Polynomial)tester.retrieve()).getExp() ){
    this.coeff = ((Polynomial)tester.retrieve()).getCoeff() + c;
    System.out.println( "this.coeff = " + this.coeff );
    with that, the output showed that e and the getExp() output were the same. it also showed (as output) that this.coeff did change in value, but when i tried this:
    System.out.println( ((Polynomial)tester.retrieve()).getCoeff() )
    to check if the value changed within the object, it didn't. this.coeff changed, but the actual coeff variable in the object didn't.
    any ideas?

  • Building a linked list

    Hi, Im having some trouble and was wondering if anyone could figure this out. I need to read in integers to build a linked list, but stuck on what to do after I read in a integer. Any help would be much appreciated!
    class lp
        public int first;
        public lp next;
        public lp(int first1, lp next1)
          first = first1; //first item in list
          next = next1; //next item in list
      public static void main(String[] args)
        int n = 0;
        Scanner sc = new Scanner(System.in);
        while(n!=-1)
        System.out.println("input: ");
        n = sc.nextInt();
        lp l = new lp(n,null); //I tried this but I get a error nonstatic variable this cannot be ref from a static context
    }Edited by: jennahogan1 on Aug 14, 2008 6:15 AM

    jennahogan1 wrote:
    A linked list is a series of nodes with an item(int, string, double, etc) and a reference to the next node in the listRight, it is a data structure as you described. Next question (which has already been asked), "Are you trying to create your own data structure or are you allowed to use Java's?"

  • Inserting into a linked list

    Hello all,
    I'm currently studying for a midterm on linked lists and I'm having a little trouble inserting in "order". What I'm trying to do is use a compareTo method to compare serial numbers of items. The compareTo methos is as follows:
    public int compareTo(Object obj) {
         StoreItem other = (StoreItem) obj;
         return serialNumber - other.serialNumber;
    And the following is my addItem method....which should simply insert the Node into the list in it's proper place according to it's serial number. Any help would be greatly appreciated:)
    public boolean addItem(StoreItem item){
    if (item == null)
    return false;
    else if (first == null)
    {first = new Node (item, null);
                return true;}
    else {
    Node p = first;
    while (p.next != null && item.compareTo(p.value) > 0){
         p = p.next;
    p.next = new Node (item, p.next);
    return true;
    Thanks again!
    Tyler

    My error lies in the "else {" section of the code....The code up to there works fine as I've tried adding one element to an empty list and print it and it works. What doesn't work is when there's already one item in my list and I want to add another, which is what the following code was meant to do:
    else {
    Node p = first;
    while (p.next != null && item.compareTo(p.value) > 0){
         p = p.next;
    p.next = new Node (item, p.next);
    return true;
    This code compiles and doesn't give me a runtime error, yet when I execute the program, it only seems to add the first element....
    Thanks again for the help:)
    Tyler

  • Doubly Linked List

    I have a doubly linked list and I wrote two methods, one to insert items at a specified index and one method to remove items at a specified index. I am not 100% sure if I wrote these methods correctly. Well I'm pretty sure I messed something up because I'm having trouble implementing a swap method and I think this is where the problem lies.
       * @param o the object to insert.
       * @param i the index to add the object.
      public void insertAt(Object o, int i) {
        if (i==0) {
          prepend(o);
        else {
          int j= 0;
          Node previous= first;
          Node next= first;
          while (j<i) {
            previous= next;
            next= previous.getNext();
            j++;
          Node insertAt= new Node(o, previous, next);
          previous.setNext(insertAt);
          insertAt.setPrevious(previous);
          insertAt.setNext(next);
          next.setPrevious(insertAt);
        size++;
       * @param i the index of the object to remove.
      public Object removeAt(int i) {
        if (i==0) {
          removeFirst();
          return first.getData();
        else {
          int j= 0;
          Node previous= first;
          Node next= first;
          while (j<i) {
            previous= next;
            next= previous.getNext();
            j++;
          Node temp=next.getNext();
          if (temp.equals(null)) {
            previous.setNext(null);
            last= previous;
            return next.getData();
          previous.setNext(temp);
          temp.setPrevious(previous);
          return next.getData();
      }

    public Object removeAt(int i) {
    if (i==0) {
    removeFirst();
    return first.getData();
    }I can't be sure from the code but the above code looks like a problem: if you remove the node before you get the data, aren't you returning the data from the second node (now the first)?

  • Java Linked List Help

    Hey,
    I am having trouble understanding the Linked List implementation code given under the Node Operations part of this pdf.
    http://www.cs.berkeley.edu/~jrs/61b/lec/07.pdf
    public ListNode(int item, ListNode next) {
    this.item = item;
    this.next = next;
    public ListNode(int item) {
    this(item, null);
    ListNode l1 = new ListNode(7, new ListNode(0, new ListNode(6)));
    I understand the earlier implementation, but this one has me confused. Would someone please go through/explain the flow of this implementation with me?
    Thanks

    Well the code is pretty self explanitory.
    a ListNode class that has two fields. an int field item, and a ListNode field next.
    so when you create a ListNode object you can do so by one of two means passing one parameter or passing two parameters.
    if you pass one parameter then you have a ListNode which has an int say 1 and a ListNode object who's value is null.
    if you pass two parameters then you have a ListNode which has an int say 2 and a ListNode object who's value is the ListNode you pass to it.
    ex ListNode myNode = ListNode(1,new ListNode(2));
    so myNode now has an integer 1 and a reference to another ListNode which has an integer value of 2 and a reference to a null ListNode.
    hope this helps.

  • How is Define Links on Confirmation Page-link list key linked to iviews?

    Hi All,
    Although there is no ESS in MSS as such in our new portal (hompage framework), we have configured it as much as we could, so that it was similar to the previous ESS in MSS.  We have used a copy of the ESS address iview for the ESS in MSS emergency contact.
    The trouble is that the links on the confirmation page are trying to resolve to ESS rather than resloving to an option in MSS.  E.G. the Go to Address Overview link is trying to resolve to the address overview screen in ESS rather than MSS.
    I have  checked the parameters on the view and there does't appear to be anywhere that you can assign the lnk list key.  Similarly I have checked the resources and the services parameters and have nowhere to put this key.
    So my question is, how exactly is the link list key attached to an iview? In our case the iviews are in 2 different PCD's so how can I create a zlink list key and assign it to the copied address iview?
    Many thanks,
    Liz.

    The confirmation links are defined in V_T7XSSSERLNK - as far as I can see they are linked to services not iviews
    defined in HpF
    Also "ESS in MSS" is available as "Self-Service for My Employee" in MSS Related Activities for certain SAP releases
    Best wishes
    Stuart

  • Question about Linked Lists

    I'm doing an assignment on linked lists and I'm having trouble understanding the insert method. I'm using the one from the book and it works fine, but I don't quite understand it.
    public void insert(Object o) {
    Node n = new Node(o,current);
    if (previous == null)
    head = n;
    else
    previous.next = n;
    current = n;
    It's my understanding that current is the value that your currently at in the list. Previous is equal to the value before the current. So, previous.next is equal to current. This reasoning won't make the list progress with this code. Can someone tell me what I'm not understanding, or explain how this progresses?

    Thanks, that helps alot. Now, I have another question. I need to add and remove nodes from the list. I have it setup where the user can choose what node to delete. It compiles and runs fine, but when I try to delete a node, it doesn't delete it. Doing some troubleshooting, I found that it gets into the for loop, but doesn't do anything with the if/else statement. I put a printline in the if and else part, and it never printed out the statement in the if statement or in the else statement. Here's the code I'm using. getLentgh() is a method I wrote to return an integer value of how many nodes are in the list. I've also tried putting in a printline after the for loop, but still in the try, it didn't print it out.
    else if(source == remove) {
    String del = JOptionPane.showInputDialog("Enter an integer to remove.");
    Node temp = new Node(del,current);
    if(del != null){
    try{
         for(int c = 0; c < list.getLength(); c++){            
         if(temp.data == current.data){
              list.remove();
              c = list.getLength();
         else{
              list.advance();     
    }catch(NullPointerException e){
    }

  • Hi i need help with my linked list

    hello
    im having trouble with my list
    this is where i create the studentlinked list. within my constructor for my college.
    public class MyCollege {
         private int capacity;
         public MyCollege(){
              StudentLinkedList studentList = new StudentLinkedList();
         }now my problem is in my add student method
    here it is.
    at the end of the method where i add the student to the linked list (studentList.add(aStudent);)is my problem. it says that studentList cannot be resolved.
    i understand that it cant find studentList. but i am creating it.
    why isnt it working???????????????????
    public static void main(String[] args) {
              MyCollege mc1 = new MyCollege();
         public void addStudent(int i){
              try{
                   Student aStudent = new Student();
                   String name,studentNumber, programmeCode;
                   int yearBegan;
                   if(i < capacity){
                        // this defines the buffer that will hold the data to be input
                        BufferedReader theDataStream;
                        theDataStream = new BufferedReader(new InputStreamReader(System.in));
                        //enter the details of the student
                        System.out.println("Enter in the name of the student followed by their student number");
                        System.out.println("followed by the year they began in the college a and then the course code");
                        System.out.println(" hit enter after each one");
                        name = theDataStream.readLine();
                        studentNumber = theDataStream.readLine();
                        yearBegan = Integer.parseInt(theDataStream.readLine());
                        programmeCode = theDataStream.readLine();
                        aStudent.setName(name);
                        aStudent.setStudentNumber(studentNumber);
                        aStudent.setYearBegan(yearBegan);
                        aStudent.setProgrammeCode(programmeCode);
                        studentList.add(aStudent);
                   }//end if
              }//end try
              catch(IOException e) {
                   System.out.println(e.getMessage());
         }

    cheers got it striaght away
         private int capacity;
         private StudentLinkedList studentList;
         

  • Constucting Doubly Linked Lists

    Hi,
    I'm trying to construct a doubly linked list with three nodes. I'm using the following code for the DLL and DLLNode classes:
    public class DLL
         public DLLNode first, last;
         public DLL()
         this.first = null;
         this.last = null;
    public class DLLNode
         protected Object element;
         protected DLLNode pred, succ;
         public DLLNode (Object elem, DLLNode pred, DLLNode succ)
         this.element = elem;
         this.pred = pred;
         this.succ = succ;
    }          and for the driver to create the DLL:
    class CreateDLLNode
    public static void main(String arg[])
         DLL zoo = new DLL();
         zoo.first = new DLLNode("ant", null, new DLLNode("bat", zoo.first, zoo.last));
         zoo.last = new DLLNode("cat",zoo.first.succ, null);
         System.out.println(zoo.first.succ.succ.element);
    }However when I run the above driver I just a null pointer exception when it tried to print the third element (i.e. cat, first's successor's successor) I've figured out that this is because the link pointing from Bat to Cat isn't there, likewise the link from Bat to Ant isn't there (get another exception if I try to print zoo.last.pred.pred). I know there's something wrong with the way I've created the DLL but I don't know what.
    I'd be very grateful for any help anyone can give, thanks!

    When you assign one variable to another (ie: thisVar=thatVar) it does not mean that thisVar will always contain whatever thatVar contains. thisVar only has what thatVar contained at the moment of the assignment.
    thisVar = 1;
    thatVar = 2;
    thisVar = thatVar;
    thatVar = 3;At the end of the above code, thisVar = 2 and thatVar = 3; thisVar does NOT equal 3.
    When you set the bat's successor to zoo.last, zoo.last is null at that moment, so bat's successor will be null. That's the basic idea of where you're going wrong with that part specifically.
    If you're going to go to the trouble of creating an abstract data structure, make the structure itself handle all these things. Give it an add() method with a parameter that accepts the objects. add() can then create a new node and supply the node the information about its previous/next nodes, and then the DLL can also change its own first/last if necessary.
    You should not have to change any of the properties of DLL outside of the DLL. When you do, you start running into problems like the one you have here.
    // assuming add at end of list
    DLL's add(elem)
        last.succ = new node(elem, last, null)
        last = last.succ
    // add in middle
    DLL's add(elem, afterThisNode)
        afterThisNode.succ = new node(elem, afterThisNode, afterThisNode.succ)
        if(afterThisNode.succ.succ)
            afterThisNode.succ.succ.pred = afterThisNodeThen you'll also need versions for where elem is going in position #1 or if it's going to be the first thing in the DLL.
    Another problem with your code too though...
    If you do "thisVar = new object( new object(thisVar))" then the "thisVar" being passed to the inner new object will have the original value of thisVar, not the value which references the outer new object. When your new bat is being made, the pred you're passing to it is also null.

  • Saving to text file from GUI within linked list

    can anyone help me with saving to a text file from a GUI text area and text fields??
    then reading back into the labels and textfields from the text file??
    It's currently just saving in a linked list and creating a new item inside of it. but i have to now make a text file for each item, this is what i currently have
    i need to turn this into something that with save to text file with buffered reader or something, can anyone help???
    public void saveToFile()
            while(listIterator.hasNext())
                item = (Item)listIterator.next();
                saving.save(item);
        }//END SAVETOFILE
        public Object save(Item item)
            if (last == 1)
                itemList.set( listIterator.nextIndex() , item);
            else
                itemList.set(listIterator.previousIndex(), item);
            itemList.set(listIterator.previousIndex(), item);
            listIterator = itemList.listIterator(0);
            return itemList.getFirst();   
        }//END SAVE

    thank you sztyopek, i am still having trouble getting it to save to text file. I have to do it through a client and server so i have a protocol class. in the protocol class i have
    if (o instanceof String)
                        //System.out.println(o);
                        if (o.equals("next"))
                            newo = database.getNextItem();
                           // some how send newo
                        if (o.equals("prev"))
                            newo = database.getPrevItem();
                            //some how send newo
                        if (o.equals("save"))
                            database.saveToFile();
                        if (o.equals("exit"))
                            System.exit(1);
                    }//END IF STRING
             if (o instanceof Item)
               newo = database.save((Item)o);
            return newo;
        }When i save what i have entered in the textfields for each record it doesn't create a textfile. and it still getting retrieved from how i set it up before by going to the database.save((Item)o)...the last if statement above but i can't change that to the saveToFile method that u helped me with it says incompatible types or something.
    this is the method it is going to, i assume i have to get rid of this so i stop getting the information from the list and start getting it from the text file.
    public Object save(Item item)
            if (last == 1)
                itemList.set( listIterator.nextIndex() , item);
            else
                itemList.set(listIterator.previousIndex(), item);
            itemList.set(listIterator.previousIndex(), item);
            listIterator = itemList.listIterator(0);
            return itemList.getFirst();   
        }//END SAVEif this makes any sense can u give me a hand.
    As to rob the guy bagging me........i am doing a bachelor of networking and they make us do java for the first year. this is my last semester and last assignment. it is also the last thing i have to do for the assignment. I am not good at java so that is why i am asking for some help i just want to pass this semester then i am never doing it again.
    thanks.

  • Link list help

    Hi, I am implementing a graph for my Java project and part of the coding requires link list for the edges.
    I wrote the code, but I just don't understand why it does not function the way like it is in C++.
    Bascilly, I have trouble adding data into a linklist
    My codes are as follows:
    public int insertLink(String fCity, String tCity, int distance)
         int location = find(fCity);
         if(location == -1)
              return -1;
         else
         insertNode(new Link(tCity,distance), location);
         return 0;     
    private void insertNode(Link node, int index)
              Link head = vertex[index].head;
              while(head != null)
                   head = head.next;
              head = node;
    This is to add stuff to the list, but for some reason, when i try to display the data, i keep getting null. somehow when
    head = node
    head = new Link(data, data);
    the head points to somwhere else, and not refer to the linklist vertex[index].head anymore...
    Here is my code to display my data:
    public void printVertex()
         for(int i = 0; i < vertex.length; i++)
              if(vertex[i] != null)
                   System.out.print(vertex[i]+" --");
                   Link node = vertex.head;
                   while(node != null)
              System.out.print(node.toCity+","+node.distance+"--");
                             node = node.next;
                   System.out.println();
    Am i doing something wrong so my linklist isn't implement correct?
    THank you.

    Hi, the "fix" for head.next != null didn't work
    private void insertNode(Link node, int index)
              Link head = vertex[index].head;
              while(head != null)
                   head = head.next;
              head = node;
              System.out.println(head.toCity+","+head.distance);
              System.out.println(vertex[index].head.toCity+","+vertex[index].head.distance);
         }basiclly. When i do System.out.println(head.toCity+","+head.distance);, it can display data
    but System.out.println(vertex[index].head.toCity+","+vertex[index].head.distance);
    it throow null's error.
    Btw, yes , i know Java have build in Link list, but unfortunately, my professor likes to reinvent the wheel and want us to do everything from scratch...
    So any other help will be useful, thank you.

Maybe you are looking for

  • Integer.parseInt() method

    Hi to all I'm trying to write a piece of a lexical analizer in Java and I need the method the does the contrary of Integer.parseInt() method in order to do the following: once i have as input an integer and with the Integer.parseInt() method i know i

  • SOLVED: is usbip usb redirector working for anyone?

    I am looking for USB redirector, and naturally tried usbip package. So far, cannot make it work: #usbipd --daemon # ps -ef | grep usbip root 16722 1 0 22:28 ? 00:00:00 usbipd --daemon # lsusb Bus 004 Device 002: ID 05da:6080 Microtek International, I

  • Cd won't eject and kernal panics: what does it mean?

    I've been getting kernal panics from time to time recently, and just last night a burned DVD refused to mount, show up in Disk Utility, or eject. i tried rebooting with the mouse down with no effect, and then i tried option-apple-O-F'ing and typing "

  • Help needed urgently: Sub-Total from Child Dataset returns 0 value

    Hi all, I REALLY need help on this I can't figure it out. I'm using rtf, bi desktop tool 11.1.5. My dataset structure is as follows: G1 Major_Service Strategy Period_Actual Period_Budget G3 WBS_Name --->=Major_Service Task_Name ---->=Strategy Forecas

  • UNICODE when Upgrading from R/3 to ECC 6.0

    I am currently working at a client who is consolidating R/3 3.1i and R/3 4.0b and upgrading these systems to ECC 6.0.  In doing so, they want to understand what considerations they need to keep into account regarding UNICODE?  They do not necessarily