Create a linked list

Hi guys!
I read the manual of java 2 and says that is not that pointers don't exist, they do exist but they are not explicit as they are in C languagge. So in need to create a circular linked list how can I do this? The instructions of the manual are not so clear. Does anyone have an idea and can give me a sample code?
Thanks to all
Maddy

References are like pointers except that you cannot make any add operation on them. But you can of course change their values to make it point to other objects.
This also means that you can create graph objects and every data structure you like. For example :
class BinaryNode {
    public Object data;
    public BinaryNode left;
    public BinaryNode right;
}To create binary trees or
class GraphNode {
    public Object data;
    public ArrayList links;
}Where links is a Java list containing a list of links (references) to other GraphNode.
Matthieu

Similar Messages

  • Need help on creating a linked list with array...

    I want to create a linked listed using array method. Any suggestion on how would I start it.
    thanks

    That means I want to implement linked list using an
    array.I believe you mean you want to implement list using an array. Linked list is a very different implementation of a list, which can be combined with arrays for a niche implementation of list, but I don't think this is what you're talking about.
    Do you mind if we ask why you don't want to use ArrayList? It does exactly what you specify, plus it will increase the size of the internal array as necessary to ensure it can store the required elements.
    If you really want to make your own, have a look at the source for ArrayList (in src.jar in your JDK installation folder) - it will answer any questions you have. If you don't understand any of the code, feel free to post the relevant code here and ask for clarification.

  • Help needed creating a linked list program

    I have been trying to create a linked list program that takes in a word and its definition and adds the word to a link list followed by the definition. i.e. java - a simple platform-independent object-oriented programming language.
    the thing is that of course words must be added and removed from the list. so i am going to use the compareTo method. Basically there a 2 problems
    1: some syntax problem which is causing my add and remove method not to be seen from the WordList class
    2: Do I HAVE to use the iterator class to go thru the list? I understand how the iterator works but i see no need for it.
    I just need to be pointed in the right direction im a little lost.................
    your help would be greatly appreciated i've been working on this over a week i dont like linked list..........
    Here are my 4 classes of code........
    * Dictionary.java
    * Created on November 4, 2007, 10:53 PM
    * A class Dictionary that implements the other classes.
    * @author Denis
    import javax.swing.JOptionPane;
    /* testWordList.java
    * Created on November 10, 2007, 11:50 AM
    * @author Denis
    public class Dictionary {
        /** Creates a new instance of testWordList */
        public Dictionary() {
            boolean done=false;
    String in="";
    while(done!=true)
    in = JOptionPane.showInputDialog("Type 1 to add to Dictionary, 2 to remove from Dictionary, 3 to Print Dictionary, and 4 to Quit");
    int num = Integer.parseInt(in);
    switch (num){
    case 1:
    String toAdd = JOptionPane.showInputDialog("Please Key in the Word a dash and the definition.");
    add(toAdd);
    break;
    case 2:
    String toDelete = JOptionPane.showInputDialog("What would you like to remove?");
    remove(toDelete);
    break;
    case 3:
    for(Word e: list)
    System.out.println(e);
    break;
    case 4:
    System.out.println("Transaction complete.");
    done = true;
    break;
    default:
    done = true;
    break;
       }//end switch
      }//end while
    }//end Dictionary
    }//end main
    import java.util.Iterator;
    /* WordList.java
    * Created on November 4, 2007, 10:40 PM
    *A class WordList that creates and maintains a linked list of words and their meanings in lexicographical order.
    * @author Denis*/
    public class WordList{
        WordNode list;
        //Iterator<WordList> i = list.iterator();
        /*public void main(String [] args)
        while(i.hasNext())
        WordNode w = i.next();
        String s = w.word.getWord();
        void WordList() {
          list = null;
        void add(Word b)
            WordNode temp = new WordNode(b);
            WordNode current,previous = null;
            boolean found = false;
            try{
            if(list == null)
                list=temp;
            else{
                current = list;
                while(current != null && !found)
                    if(temp.object.getWord().compareTo(current.object.getWord())<0)
                        found = true;
                    else{
                    previous=current;
                    current=current.next;
                temp.next=current;
                if(previous==null)
                    list=temp;
                else
                    previous.next=temp;
                }//end else
            }//end try
            catch (NullPointerException e)
                System.out.println("Catch at line 46");
        }//end add
    /*WordNode.java
    * Created on November 4, 2007, 10:40 PM
    *A class WordNode that contains a Word object of information and a link field that will contain the address of the next WordNode.
    * @author Denis
    public class WordNode {
        Word object;//Word object of information
        WordNode next;//link field that will contain the address of the next WordNode.
        WordNode object2;
        public WordNode (WordNode wrd)
             object2 = wrd;
             next = null;
        WordNode(Word x)
            object = x;
            next = null;
        WordNode list = null;
        //WordNode list = new WordNode("z");
        Word getWord()
            return object;
        WordNode getNode()
            return next;
    import javax.swing.JOptionPane;
    /* Word.java
    * Created on November 4, 2007, 10:39 PM
    * A class Word that holds the name of a word and its meaning.
    * @author Denis
    public class Word {
        private String word = " ";
        /** Creates a new instance of Word with the definition*/
        public Word(String w) {
            word = w;
        String getWord(){
            return word;
    }

    zoemayne wrote:
    java:26: cannot find symbol
    symbol  : method add(java.lang.String)
    location: class Dictionary
    add(toAdd);this is in the dictionary class
    generic messageThat's because there is no add(...) method in your Dictionary class: the add(...) method is in your WordList class.
    To answer your next question "+how do I add things to my list then?+": Well, you need to create an instance of your WordList class and call the add(...) method on that instance.
    Here's an example of instantiating an object and invoking a method on that instance:
    Integer i = new Integer(6); // create an instance of Integer
    System.out.println(i.toString()); // call it's toString() method and display it on the "stdout"

  • Need help with creating a linked list

    I need to create a linked list that i can put numbers or an operator into
    class Number_or_op
    boolean flag;
    double number;
    char operator;
    Number_or_op(boolean flag1,double number1,char operator1)
    flag = flag1;
    number = number1;
    operator = operator1;
    class Expr {
    Number_or_op first;
    Expr rest;
    Expr(Number_or_op first1,Expr rest1)
    first = first1;
    rest = rest1;
    how do i make a linked list out of this? im trying
    Expr list1 = new Expr(3, new Expr('*' , new Expr(4 , null)));
    but keep getting an error D:\Documentation\expr.java:14: internal error; cannot instantiate Expr.<init> at Expr to ()
    how do i fix the number_or_op so it can make it into a list?

    Let me reitterate my problem because i am so lost...
    I am used to making linked list using an integers only.. and now my teacher wants me to use both integers and chars, the chars being operators..
    I have no idea how to do that using hte code he provided because it makes no sense at all to me
    class Number_or_op
    boolean flag;
    double number;
    char operator;
    Number_or_op(boolean flag1,double number1,char operator1)
    flag = flag1;
    number = number1;
    operator = operator1;
    class Expr {
    Number_or_op first;
    Expr rest;
    Expr(Number_or_op first1,Expr rest1)
    first = first1;
    rest = rest1;
    I need to make a list that looks like 1 + 3 / 4 each operator or number needs a different node.. i just cant think of how to do it and keep getting an error message everytime i do saying:
    File: D:\Documentation\expr.java [line: 14]
    Error: D:\Documentation\expr.java:14: internal error; cannot instantiate Expr.<init> at Expr to ()
    I just dont know what to do

  • How can you create a linked list? GUI?

    I have the following program that I wrote:
    package damagecounter;
    import java.io.*;
    import java.util.*;
    public class Main
         public static void main (String[] args) throws Exception
              String logline;
              Player player1 = new Player("Kazzandar");
              try
                   BufferedReader logfile = new BufferedReader(new FileReader("TeilmonRun.txt"));
                   logline = logfile.readLine();
                   while (logline != null)
                        if (logline.startsWith (player1.getName (), 0))
                             if (logline.contains ("recites"))
                                  player1.recites++;
                             if (logline.contains ("rescues"))
                                  player1.rescues++;
                             if (logline.contains ("utters the words"))
                                  player1.spells++;
                             if (logline.contains ("sprawling with a powerful bash."))
                                  player1.bashes++;
                             if (logline.contains ("got toasted by"))
                                  player1.deaths++;
                             if ((logline.contains ("-=")) && (logline.contains ("=-")))
                                  if (logline.startsWith (player1.getName (), 0))
                                       String damage = logline.substring(logline.indexOf ("-=") + 2 , logline.indexOf ("=-"));
                                       player1.setDamage (Integer.parseInt (damage));
                        logline = logfile.readLine ();
              catch (Exception e)
                   System.out.println ("Log file not found or corrupt.");
                   e.printStackTrace();
              player1.printStats();
    }As of right now the code require a person to enter the name of a player and then scans the log file to determine the appropriate counts for that player. If I want to scan the file for multiple players how would I be able to do that without having to run the program over and over. The reason being that sometimes the logs have over 15 different players and I'd hate to have to run the program 15 times to get each players stats. Any suggestions? Would I have to make a linked list?

    Yes, the log file looks something like that. Here is a small 15 line version of what the log file actually looks like:
    Kazzandar's stab misses Icingdeath. -=0=-
    Arien's slash >>> ANNIHILATES <<< Icingdeath! -=118=-
    Arien's slash >>> ANNIHILATES <<< Icingdeath! -=112=-
    Arien's slash <<< ERADICATES >>> Icingdeath! -=158=-
    Parrish utters the words, 'yjrr pzar'.
    Arien rescues Shargaas!
    Kazzandar's counterattack does UNSPEAKABLE things to Icingdeath! -=636=-
    Icingdeath's claw does UNSPEAKABLE things to Arien! -=760=-
    Arien's fireball scratches Icingdeath. -=4=-
    Arien's lightning bolt grazes Icingdeath. -=7=-
    Arien's counterattack -- DESSICATES -- Icingdeath! -=540=-
    Icingdeath's claw COMPLETELY TRASHES Arien! -=802=-
    Arien is DEAD!
    Kitiara's fireball grazes Icingdeath. -=5=-
    Kitiara's lightning bolt grazes Icingdeath. -=8=-
    Almost always the player name is first but sometimes the "mob" name (In this case Icingdeath) comes out. I don't mind if Icingdeath is referenced as a player and included in the stats, not that big a deal. Thanks for the idea on the HashMap I'll looking into how it works. Since this is my first Java program I often find myself lost at where to begin.
    I changed "got toasted by" to "is DEAD!" since it's easier to read. I also changed the majority of the main code into a method for the player class. The main code looks like this now:
    public static void main (String[] args) throws Exception
              Player player1 = new Player("Shargaas");
              player1.scanLogForStats("TeilmonRun.txt");
              player1.printStats();
         I was hoping this would make it easier, anyway, thanks again and I'll definitely be looking into HashMap.

  • How to create two linked lists (Master/Detail or Parent/Child)

    I need to create a couple of related lists in a Master/Detail approach. Users are supposed to choose one "Master" Option, and "Detail" column should be refreshed to display only the items that are strictly related to the chosen option
    in "Master". Any posible solution?
    Thanks in advance.

    One option is to connect two web parts. This will give you option button for your master list web part and based on the value selected your results will be filtered in the detailed list web part. Here is the example. Though it is for SP 2010 it should work
    the same in SP 2013.
    http://sarahlhaase.wordpress.com/2012/05/21/connecting-web-parts-with-a-selector-and-a-detail-pane-sharepoint-2010-version/
    Second option is with some customization using Jquery.
    http://summit7systems.com/creating-a-parentchild-list-relationship-in-sharepoint-2013/
    Amit

  • How do you create a linked list

    i need a linked list to hold data which would be words so that the words can be held by the linked list and appear in alphabetica order?

    public class DoubleLink1
         private NodeData head;
         private NodeData tail;
         public DoubleLink1()
         this.tail = null;
         this.head = null;
         public void add(Contact info)
         NodeData newNode = new NodeData(info);
         if(head != null)
         newNode.next = head;
         head.prev = newNode;
         head = newNode;
         else
         head = tail = newNode;
         public Contact retrieve(String name)
         NodeData current = head;
         while(current !=null)
         if(current.data.getName().equals(name))
         return current.data;
         current = current.next;
         return null;
         public void traverse()
         NodeData current = head;
         while(current !=null)
    //     current.getData());print();
         current = current.next;
         public boolean delPhoneNum(String name)
         NodeData current = head;
         NodeData previous = head.prev;
         NodeData next = head.next;
         boolean found = false;
         if (head == null)
         return false;
         while(current != null)
         if(current.data.getName().equals(name))
         found = true;
         return found;
         previous = current;
         current = current.next;
         if (current != null)
         next = current.next;
         if (found)
         if (previous == null)
         head = head.next;
         else if (next == null)
         tail = tail.prev;
         else
         previous = current.next;
         next = current.prev;
         return found;
         }//DoubleLink
    so i have this linked list..how can i apply it to my program with the words instead of the numbers and phone contact

  • Alphabetizing a linked list, HELP!

    To all:
    Firstly, I'm not looking for someone to do my assignment for me. I just need a push in the right direction...
    I need to create a linked list that contains nodes of a single string (a first name), but that list needs to be alphabetized and that's where I am stuck.
    I can use an iterator method that will display a plain-old "make a new node the head" linked list with no problem. But I'm under the impression that an iterator method is also the way to go in alphabetizing this list (that is using an iterative method to determine the correct place to place a new node in the linked list). And I am having zero luck doing that.
    The iterator method looks something like this:
    // ---- MyList: DisplayList method ----
    void DisplayList()
    ListNode p;
    for (ResetIterator(); (p = Iterate()) != null; )
    p.DisplayNode();
    // ---- MyList: ResetIterator method ----
    void ResetIterator()
    current = head;
    // ---- MyList: Iterate method ----
    ListNode Iterate()
    if (current != null)
    current = current.next;
    return current;
    Can I use the same iterator method to both display the final linked list AND alphabetize my linked list or do I need to create a whole new iterator method, one for each?
    Please, someone give me a hint where to go with this. I've spent something like 15 hours so far trying to figure this thing out and I'm just stuck.
    Thanks so much,
    John
    [email protected]

    I'll try and point you in the right direction without being too explicit as you request.
    Is your "linked list" an instance of the Java class java.util.LinkedList or a class of your own?
    If it is the Java class, then check out some of the other types of Collections that provide built-in sorting. You should be able to easily convert from your List to another type of Collection and back again to implement the sorting. (hint: you can do this in two lines of code).
    If this is your own class and you want to code the sort yourself, implement something simple such as a bubble sort (should be easy to research on the web).
    Converting to an array, sorting that and converting back is another option.
    Good Luck.

  • Constructing a linked list from an array of integers

    How do I create a linked list from an array of 28 integers in a constructor? The array of integers can be of any value that we desire. However we must use that array to test and debug methods such as getFirst(), getLast(), etc...
    I also have a method int getPosition(int position) where its suppose to return an element at the specified position. However, I get an error that says cannot find symbol: variable data or method next()
    public int getPosition(int position){
         LinkedListIterator iter=new LinkedListIterator();
         Node previous=null;
         Node current=first;
         if(position==0)
         return current.data;
         while(iter.hasMore()){
         iter.next();
         if(position==1)
         return iter.data;
         iter.next();
         if(position==2)
         return iter.data;
         iter.next();
         if(position==3)
         return iter.data;
         iter.next();
         if(position==4)
         return iter.data;
         iter.next();
         if(position==5)
         return iter.data;
         iter.next();
         if(position==6)
         return iter.data;
         iter.next();
         if(position==7)
         return iter.data;
         iter.next();
         if(position==8)
         return iter.data;
         iter.next();
         if(position==9)
         return iter.data;
         iter.next();
         if(position==10)
         return iter.data;
         iter.next();
         if(position==11)
         return iter.data;
         iter.next();
         if(position==12)
         return iter.data;
         iter.next();
         if(position==13)
         return iter.data;
         iter.next();
         if(position==14)
         return iter.data;
         iter.next();
         if(position==15)
         return iter.data;
         iter.next();
         if(position==16)
         return iter.data;
         iter.next();
         if(position==17)
         return iter.data;
         iter.next();
         if(position==18)
         return iter.data;
         iter.next();
         if(position==19)
         return iter.data;
         iter.next();
         if(position==20)
         return iter.data;
         iter.next();
         if(position==21)
         return iter.data;
         iter.next();
         if(position==22)
         return iter.data;
         iter.next();
         if(position==23)
         return iter.data;
         iter.next();
         if(position==24)
         return iter.data;
         iter.next();
         if(position==25)
         return iter.data;
         iter.next();
         if(position==26)
         return iter.data;
         iter.next();
         if(position==27)
         return iter.data;
         iter.next();
         if(position==28)
         return iter.data;
         if(position>28 || position<0)
         throw new NoSuchElementException();
         }

    How do I create a linked list from an array of 28 integers
    in a constructor? In a LinkedList constructor? If you check the LinkedList class (google 'java LinkedList'), there is no constructor that accepts an integer array.
    In a constructor of your own class? Use a for loop to step through your array and use the LinkedList add() method to add the elements of your array to your LinkedList.
    I get an error that
    says cannot find symbol: variable data or method
    next()If you look at the LinkedListIterator class (google, wait for it...."java LinkedListIterator"), you will see there is no next() method. Instead, you typically do the following to get an iterator:
    LinkedList myLL = new LinkedList();
    Iterator iter = myLL.iterator();
    The Iterator class has a next() method.

  • Help on Linked List

    Hey people, i need a small help on my linked list.
    Ok, what i'm trying to do is have a search function with a linked list using strings. First i will have a string, i will then compute the ASCII value for that and take MOD 71 lets say. For example, a string has an ASCII value of 216, MOD 71 of this gives me 3. I will then have an array of 71, and each array will point to a linked list. There will be as many linked list as there are of arrays (71). I will then store this string at index [3] in the linked list in which the array points to.
    My problem for now is, how do i for example create 71 linked list? So far i can create only 1. To create another is easy, but if i have 71 the code will be too much. Is there an iterator i could use that easily creates 71? Sorry about this, i'm not really good with linked list with Java. Anyway, here is what i have now :).
    public class MyLinkedListElement {   
            String string;
            MyLinkedListElement next;
            public MyLinkedListElement(String s) {   
                string = s;
                next = null;   
            public MyLinkedListElement getNext() {
                return next;       
            public String getValue() {
                return string;
    public class MyLinkedList {
        public static MyLinkedListElement head;
        public MyLinkedList() {   
            head = null;
       public static void addToHead(String s) {
            MyLinkedListElement a = new MyLinkedListElement(s);
            if (head == null) {
                head = a;
            } else {
                a.next = head;
                head = a;       
        public static void main(String[] args) {
              String[] arr = {"Bubble", "Angie", "Bob", "Bubble", "Adam"};
              for (int i = 0; i < arr.length; i++) {
                          addToHead(arr);
    MyLinkedListElement current = head;
    while (current != null) {
    System.out.println(current.getValue());
    current = current.next;
    }I can have an array of strings and easily add them to a linked list.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I am very confused now, i just need to store a string value inside an array of linked list. But i can't somehow do it. I am very close, i can store the value in a linked list but the array of linked list, this is what i have.
    public class MyLinkedListElement {   
            String string;
            MyLinkedListElement next;
            public MyLinkedListElement(String s) {   
                string = s;
                next = null;   
            public MyLinkedListElement getNext() {
                return next;       
            public String getValue() {
                return string;
    public class MyLinkedList {
        public MyLinkedListElement head;
        public MyLinkedList() {   
              head = null;
        public void addToHead(String s) {
             MyLinkedListElement  a = new MyLinkedListElement(s);
             MyLinkedList[] arrayOfLinkedLists = new MyLinkedList[71];
             for(int i = 0; i < arrayOfLinkedLists.length; i++) {
                 arrayOfLinkedLists[i] = new MyLinkedList();
             if (head == null) {    
                 head = a;
             } else {
                 a.next = head;
                 head = a;       
        public void print(MyLinkedListElement current) {
              while (current  != null) {
                    System.out.println(current.getValue());
                    current = current.next;
        public static void main(String[] args) {
              String[] arr = {"Bubble", "Angie", "Bob", "Bubble", "Adam"};
              MyLinkedList listInstance = new MyLinkedList();
              for (int i = 0; i < arr.length; i++) {
                    listInstance.addToHead(arr);
    MyLinkedListElement current = listInstance.head;
    listInstance.print(current);

  • Linked List mess

    Hello,
    I think I've gotten myself into a bit of a mess.
    I create a Linked List containing many strings. I do this for 10 separate tabs. I then want to combine Linked Lists into something else like a LinkedList again so I can then write that one combined list to a file. Something like an array but instead it takes in LinkedLists.
    The container of the 10 linked lists will never have more than 10 but will always have 10. If one of the tabs is not enabled I place a filler in for it. This is my code and it is throwing me a null pointer exception and I am sure it is because I initialize CETotalCover to null but I don't know how else I could initialize it. That leads me to believe this is probably not the right choice for what I am doing.
    LinkedList<String>[] CETotalCover = null;     
    LinkedList<String> noCover = new LinkedList();
    noCover.add("***");
    CEArray CEData = new CEArray();
    if (_Dailycover.isEnabled()){
         CETotalCover[0] = CEData.toLayer(_Dailycover.getRowData());
    else{
         CETotalCover[0] = noCover;
    }What would be the best way to do this? Sorry I'm new to Java and haven't had much experience with trying to make a list of lists.
    Edited by: Sch104 on May 19, 2008 10:25 AM
    Edited by: Sch104 on May 19, 2008 10:25 AM

    Correct, you never created an array object to store your lists in, so when you tried to access the first element it blew up. In order to fix that, you need to actually create the array. Unfortunately, generics and arrays do not play nicely together. Use an ArrayList instead.

  • Comparable linked list sorting

    i have been trying to find a way to sort a link listed. After some reading i found out that it is probably best to use collections.sort(list). I think i understand how to implement it , i need to declare a compareto and equals method. However, most of the reading i have done shows how to create a collection from a linked list and add items to the collection and sort them, however it doesn show how to copy this sorted collection back inot a linked list. I need to remove items and add items to the sorted linked list. Is it possible to create a linked list, sort it using the collection sort and return the sorted linked list? I have looked in the api's but got confused!!

    You don't need to copy anything.
    List list = new LinkedList(); // or ArrayList
    // list.add stuff
    Collections.sort(list); Assuming whatever you added to the list implements Comarable, the list is now sorted.

  • C/C++ Alphabetical Linked List

    For my programming class, we have to create a linked list, which is arranged in order of when you added them. This was Assignment Six. Assignment 8 is to add an alphabetical list to this program, alongside the list in order.
    My professor wants us to have a "donor struct" and an "alpha struct" that points to the donor, as well as the next in the list.
    He isn't helping me figure this out so I figured I'd ask for help here.
    My 'modifyDonor()' function is broken, it deletes everything after whatever record you are trying to modify. There is also a problem in my 'prepareFiles()' function. Whatever the last entry is, is copied in twice.
    I would rather have this alphabetical stuff figured out before I work on those things.
    I'm not really allowed to use C++ stuff (classes, objects, etc.), because we haven't learned them yet, but if you can do it, and figure it out, then explain it to me. I'll take it.
    (Also, if you could post the edits to my source code, that would rad!)
    Below is a link to my source code and data file.
    http://www.dcpwrpodcast.com/DCPWR/Help.Sponsorhipfiles/Archive.zip
    Any help you can provide is greatly appreciated!

    Unfortunately, I can't really pinpoint an exact place where you are doing something wrong. I don't think you really understand the linked list concepts yet. The first thing I changed was getting rid of where you increment "first" in modifyDonation. Resetting "first" effectively destroys your list. You have additional problems with the other pointers.
    So, first of all, you have too many global pointers. You need one global pointer, named "head". Any time you iterate through the list (to print, find, etc.) you create a temp donor pointer, assign "head" to it and increment that temp pointer. The last node in your list should have NULL as its "next" pointer.
    To add a node, create a new node with NULL as its next pointer. Find where you want to insert, make the new node's next pointer point to the next pointer of the node at the insertion point. Then make the next pointer of the node at the insertion point point to the new node.
    To delete a node, find the node to delete. Make the previous node's next pointer point to the dead node's next pointer. Then delete the node.
    You don't change any pointers (other than temp ones) during a modify or print.
    At this point, all you have left is the special case of the first node. The last node isn't special because you can do the same copying of the next pointer as normal, even though that pointer is NULL.
    The first node, however, needs careful handling. If you delete the first node, you have to reset your head pointer. If you insert a new first node, you have to reset your head pointer. Sometimes it is easier to have your head node be a special, empty node. Then, you don't have to re-assign head. Also, when searching through the list, your "current" pointer should be the "previous" node. That way, when you are ready to insert, your "current" pointer is the "previous" node and the insertion is easy. The code looks a bit ugly because you'll have things like "if(current->next && current->next->id == id)". But you'll also need an extra, redundant null check.
    Hopefully this makes some sense. Your code is more complicated than it needs to be. You have too many globals. You are modifying those globals far too frequently. You want lots of:
    void modifyDonation(donor * node);
    donor * current = head->next;
    while(current)
    if(current->id == id)
    modifyDonation(current);
    break;
    current = current->next;
    insert and delete are more difficult
    void insertDonation(donor * previous, donor * next);
    donor * current = head;
    while(current)
    if(!current->next || (current->next->id == id))
    insertDonation(current, current->next);
    break;
    current = current->next;
    To maintain a natural order and a sorted order, you'll need two head pointers. After you add or insert into the natural list, you insert into the sorted list according to the sort criteria. Delete is the same for both lists.

  • Linked lists in labview

    Hi
    I want to create a linked list in labview. How can i do that in labview?
    If its not possible how can i implement in labview?

    I'd say one of the best implementations of a linked list is an Array of DVR's, just like you can have an array of pointers in C, the next and previous is ofc the place in the array. The question if ofc what you're trying to achieve.
    A "pure linked list" require a Cluster with a Next and Previous-DVR (or the name of a queue, though i dont know how the system would handle having thousands of 1-element queues) and either a Self-DVR or the information.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • Object linked list

    Hi am trying to create a linked list out of an object i have called ClassID.
    I have a Link class (that creates a node correct?):
    import java.io.*;
    public class Link
         public ClassID id;
        public Link next;
         public Link(ClassID inID)
              this(inID, null);
        public Link(ClassID inID, Link next)
            id = inID;
            next = next;;
         public void displayLink() // display ourself
              id.toString();
    } // end class LinkIf it does create node then I have a class called LinkList with the following insert method:
    private Link first; // ref to first link on list
    // insert at start of list
         public void insertFirst(Link id)
         { // make new link
              Link newLink = new Link(id);
              newLink.next = first; // newLink --> old first
              first = newLink; // first --> newLinkBut it doesnt seem to be working, could someone help me.
    Thanks
    Phil
    Edited by: The_One on Sep 13, 2008 1:49 AM

    I dont think its doing it properly. Iv tried goign through it but cant find the problem. Might be a problem with displaylist
    Let me paste all my classes:
    LINK METHOD:
    import java.io.*;
    public class Link
         public ClassID id;
        public Link next;
         public Link(ClassID inID)
              this(inID, null);
        public Link(ClassID inID, Link next)
            id = inID;
            next = next;;
         public void displayLink() // display ourself
              id.toString();
    } // end class LinkLINKLIST METHOD:
    class LinkList
         private Link first; // ref to first link on list
         public LinkList() // constructor
              first = new Link(null); // no items on list yet
         public boolean isEmpty() // true if list is empty
              return (first==null);
         // insert at start of list
         public void insertFirst(ClassID id)
         { // make new link
              Link newLink = new Link(id);
              newLink.next = first; // newLink --> old first
              first = newLink; // first --> newLink
    public void displayList()
              System.out.print("List (first-->last): ");
              Link current = first; // start at beginning of list
              while(current != null) // until end of list,
                   current.displayLink(); // print data
                   current = current.next; // move to next link
              System.out.println("");
    ................. SOME MORE METHODS..........MAIN METHOD:
    import java.io.*;
    public class SortListApp
        public static void main(String[] args)
         BufferedReader inputStream = null;
         LinkList list = new LinkList();
         try
              inputStream = new BufferedReader(new FileReader("data.txt"));
               String inName;
              int inIDNum;
              int inACNum;
              long inTime;
              int inTransmode;
              //while ((inName = (inputStream.readLine()) ) != null)
                   inName = inputStream.readLine();
                   inIDNum = Integer.parseInt(inputStream.readLine());
                   inACNum = Integer.parseInt(inputStream.readLine());
                   inTime = Long.parseLong(inputStream.readLine());
                   inTransmode = Integer.parseInt(inputStream.readLine());
                   list.insertFirst(new ClassID(inName, inIDNum, inACNum, inTime, inTransmode));                    
              list.displayList();
              //System.out.println("Printed to file");
              //list.sort();
              inputStream.close();
         catch (IOException error)
              System.out.println("Error in file");
    }Edited by: The_One on Sep 13, 2008 2:41 AM

Maybe you are looking for

  • How to manage 2 ipads in family (trying to update games on both)

    Hi all, a few questions please. I am trying to sort out the 2 ipads so its more easy to manage. I am trying to use one for work so trying to make sure that emails etc do not go to both but still allowing the kids to play on both when I am at home. 1)

  • Images won't display on my webpages with Rapidweaver 5

    For some reason I can't see any pictures on my website once it's published onto my website. The pictures won't load on my website. At first I thought that there was a conflict with my APPS because i have other APPS on my Mac too. So I've formatted my

  • Displaying a message when there are no results from an XSL Query

    Using MM_XSLTransform.class.php I am querying an XML file to produce a list of places whose town name or address match a letter of the alphabet. The letter is passed as a variable in a URL. XSL: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.

  • I need a solution for node-webkit and libudev.so.0

    Hello there! I'm developing the package of node-webkit in the aur. Since the first time I had trouble with libudev.so.0. The first quick fix was to generate a symbolic link to libudev.so.1, but this is not the best way and can destabilize the system.

  • Periodic Extract from FAGLFLEXT - NewGL ?

    Hi everyone, we are implementing a BCS system and want to transfer the totals from a migrated NewGL-System. Migration has been done to the beginning of this year, the old GL ist still for comparison reasons active. In the confuguration of the NewFL,