Turning a linked list into a for loop

Im stupid and cannot figure out how to make this
lp list1 = new lp(0,new lp(1, new lp(2, new lp(3, new lp(4, new lp(5, new lp(6, new lp(7, new lp(8, new lp(9, null))))))))));
into a for loop, i know its simple, i finished my first linked list assignmenet but having this in my program is too ugly and i know a loop should fix it

JosAH wrote:
cotton.m wrote:
Ip list = new IP(9,null);
for(int i descending order starting from 8 and going down to zero)
list = new Ip(i,list);
That last/first element can be in the loop too:
Ip list = null;
for(int i descending order starting from 9 and going down to zero)
list = new Ip(i,list);
}kind regards,
Josd'oh! Yes that's better. Thanks.

Similar Messages

  • How to pass parameter into cursor for loop ?

    Hi Experts,
    I want to pass parameter l_bom_header_tbl(i).assembly_item_name into the for statement below How to achieve this?
    for j in 1 .. l_bom_components_tbl.COUNT LOOP
    Thanks

    Maybe i failed to describe in detail,so here i go:
    I have two for loops:
    for i in 1 .. l_bom_header_tbl.COUNT LOOP --1st For Loop
    V_bom_header_tbl.organization_code :='DSC';
    V_bom_header_tbl.assembly_item_name:= l_bom_header_tbl(i).assembly_item_name ;
    k:=1;
    I want to pass parameter l_bom_header_tbl(i).assembly_item_name into the for statement below: How to achieve this?
    for j in 1 .. l_bom_components_tbl.COUNT LOOP *2nd For Loop*
    v_bom_components_tbl(k).Assembly_Item_name := l_bom_header_tbl(i).assembly_item_name ;
    k := k + 1;
    end LOOP;
    end loop;
    end;
    I want to pass a paramter into second for loop in such a way that it accepts from the first for loop
    for j in 1 .. l_bom_components_tbl.COUNT LOOP -2nd loop
    Edited by: ILovePlSql on Mar 22, 2010 12:25 PM

  • User request to explore the possibility of downloading the distribution lists into excel for maintenance in t-code SO23.

    Hi Experts,
    There is a requirement from user that  "To explore the possibility of downloading the distribution lists
    into excel for maintenance in t-code SO23 ".
    Kindly provide your valuable informations/assistance in this regard.
    Madhavan K

    This Applesctipt will add comma's to the file count:
    (Copy into Applescript Editor, and Save as File Format: App, then just click the App to run)
    set x to choose folder with prompt "Choose Folder to Count Files" default location alias (the path to pictures folder as text)
    set filecount to do shell script "find " & POSIX path of x & " ! -type d ! \\( -name \".*\" -or -name \"Icon*\" \\) | wc -l"
    display dialog "File Count: " & comma_delimit(trim(filecount))
    on trim(someText)
              repeat until someText does not start with " "
                        set someText to text 2 thru -1 of someText
              end repeat
              repeat until someText does not end with " "
                        set someText to text 1 thru -2 of someText
              end repeat
              return someText
    end trim
    on comma_delimit(this_number)
              set this_number to this_number as string
              if this_number contains "E" then set this_number to number_to_text(this_number)
              set the num_length to the length of this_number
              set the this_number to (the reverse of every character of this_number) as string
              set the new_num to ""
              repeat with i from 1 to the num_length
                        if i is the num_length or (i mod 3) is not 0 then
                                  set the new_num to (character i of this_number & the new_num) as string
                        else
                                  set the new_num to ("," & character i of this_number & the new_num) as string
                        end if
              end repeat
              return the new_num
    end comma_delimit

  • Turn long url list into active links

    I have a long list of complete internet addresses (URLs) and I want them all to be Hyperlinks but don't want to specify each one separately (It would take forever. Is there any way for Pages to turn these text URLs into links?

    Hello there, stockybobby.
    The following link to the Pages Help for Mac provides some great information regarding hyperlinks:
    Create links for websites and email addresses - Pages Help for Mac
    http://help.apple.com/pages/mac/5.2/#/tand51db403
    Create links for websites and email addresses
    Pages automatically detects website addresses (URLs) and email addresses you type and formats them as active links. You can edit these links or deactivate them so that they appear and behave as normal text.
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • Reasons why to use Iterator for List rather than for loop ?

    when i use the iterator and for loop for traversing through the list. it takes the same time for iterator and also for for loop. even if there is a change it is a minor millisecond difference.
    what is the actual difference and what is happening behind the traversing list through iterator
    if we are using we are importing extra classes ...if we are using for loop there is no need to import any classes

    If you have an array-backed collection, like an ArrayList, then the difference between using an iterator and get() will be negligible.
    However, if you have a linked list, using get() is O(n^2) whereas iterator is O(n).
    So with an iterator, regardless of what your underlying data structure, a list of 100,000 elements takes 1,000 times as long to iterate over as a list with 100 elements. But using get() on a LinkedList, that same 100,000 element list will take 1,000,000 times as long as the 100 item list.
    There's no real benefit to ever using get()
    Side note: I've been comparing iterators to get(), not iterators to for loops. This is because whether it's a for or a while has nothing to do with whether you use an iterator or get(). The way I use iterators is for (Iterator iter = list.iterator(); iter.hasNext(); ) {
        Foo foo = (Foo)iter.next();
    }

  • Can I import my old link lists into 365 site?

    Hi I would like to import all my hard work from my old 2010 sharepoint site into the new 365 site.
    I exported my links to excel but I cannot see an import option on a link list in 365.
    Surely there must be an easy way to do this that I am missing?
    thanks

    Below are the steps to save List as Template:
    >> Go to the List - List Settings - Click on Save List as Template - Provide Template Name and make sure you check the "With Content" box available on the page. 
    Once the List is successfully saved as template, you will find the template under List Templates gallery. Download that template it should have ".stp" extension. Get that file and upload the file to List Templates gallery of your SharePoint Online Office
    365 site. Then create a new app and there you should find the Template and create a list using that template.
    If you have any questions then let me know.
    Please ensure that you mark a question as Answered once you receive a satisfactory response.

  • Which is better ListIterator or Simple list.size() in for loop

    Hi everybody
    I have one scenario in which, I need to delete the duplicate values from the list (Note : Duplicate values are coming in sequence).
    I tried to approaches as follows
    1) Using ListIterator
    I iterated all values and if I found any duplicate then I called remove() method of Iterator.
    2) I made another ArrrayList object, and iterated the old list using size() and for loop, and if I found unique value then I added that value to the new ArrayList.
    I also created one test java file to find out the performance in both cases. But I am not pretty sure that this test is correct or not. Please suggest me which approach is correct.
    code For Test
    public class TestReadonly {
         public static void main(String[] args) {
              List list = new ArrayList();
              long beforeHeap = 0,afterHeap = 0;
              long beforeTime = 0,afterTime = 0;
              addElementsToList(list);
              Collections.sort(list);
              callGC();
              beforeHeap = Runtime.getRuntime().freeMemory();
              beforeTime = System.currentTimeMillis();
              System.out.println(" Before "+System.currentTimeMillis()+" List Size "+list.size()+" heap Size "+beforeHeap);
              new TestReadonly().deleteDuplicated1(list);
              afterHeap = Runtime.getRuntime().freeMemory();
              afterTime = System.currentTimeMillis();
              System.out.println(" After  "+System.currentTimeMillis()+" List Size "+list.size()+" heap Size "+afterHeap);
              System.out.println(" Time Differance "+(afterTime-beforeTime)+" Heap Differance "+(afterHeap-beforeHeap));
              list.clear();
              addElementsToList(list);
              Collections.sort(list);
              callGC();
              beforeHeap = Runtime.getRuntime().freeMemory();
              beforeTime = System.currentTimeMillis();
              System.out.println(" Before "+System.currentTimeMillis()+" List Size "+list.size()+" heap Size "+beforeHeap);
              list = new TestReadonly().deleteDuplicated2(list);
              afterHeap = Runtime.getRuntime().freeMemory();
              afterTime = System.currentTimeMillis();
              System.out.println(" After  "+System.currentTimeMillis()+" List Size "+list.size()+" heap Size "+afterHeap);
              System.out.println(" Time Differance "+(afterTime-beforeTime)+" Heap Differance "+(afterHeap-beforeHeap));
          * @param list
         private static void addElementsToList(List list) {
              for(int i=0;i<1000000;i++) {
                   list.add("List Object"+i);
              for(int i=0;i<10000;i++) {
                   list.add("List Object"+i);
         private static void callGC() {
              Runtime.getRuntime().gc();
              Runtime.getRuntime().gc();
              Runtime.getRuntime().gc();
              Runtime.getRuntime().gc();
              Runtime.getRuntime().gc();
         private void deleteDuplicated1(List employeeList) {
              String BLANK = "";
              String currentEmployeeNumber = null;
              String previousEmployeeNumber = null;
              ListIterator iterator = employeeList.listIterator();
              while (iterator.hasNext()) {
                   previousEmployeeNumber = currentEmployeeNumber;
                   currentEmployeeNumber = (String) iterator.next();
                   if ((currentEmployeeNumber.equals(previousEmployeeNumber))
                             || ((BLANK.equals(currentEmployeeNumber) && BLANK
                                       .equals(previousEmployeeNumber)))) {
                        iterator.remove();
         private List deleteDuplicated2(List employeeList) {
              String BLANK = "";
              String currentEmployeeNumber = null;
              String previousEmployeeNumber = null;
              List l1 = new ArrayList(employeeList.size());
              for (int i =0;i<employeeList.size();i++) {
                   previousEmployeeNumber = currentEmployeeNumber;
                   currentEmployeeNumber = (String) employeeList.get(i);
                   if (!(currentEmployeeNumber.equals(previousEmployeeNumber))
                             || ((BLANK.equals(currentEmployeeNumber) && BLANK
                                       .equals(previousEmployeeNumber)))) {
                        l1.add(currentEmployeeNumber);
              return l1;
    Output
    Before 1179384331873 List Size 1010000 heap Size 60739664
    After 1179384365545 List Size 1000000 heap Size 60737600
    Time Differance 33672 Heap Differance -2064
    Before 1179384367545 List Size 1010000 heap Size 60739584
    After 1179384367639 List Size 1000000 heap Size 56697504
    Time Differance 94 Heap Differance -4042080

    I think, you test is ok like that. Although I would have tested with two different applications, just to be shure that the heap is clean. You never know what gc() actually does.
    Still, your results show what is expected:
    Approach 1 (List iterator) takes virtually no extra memory, but takes a lot of time, since the list has to be rebuild after each remove.
    Approach 2 is much faster, but takes a lot of extra memory, since you need a "copy" of the original list.
    Basically, both approaches are valid. You have to decide depending on your requirements.
    Approach 1 can be optimized by using a LinkedList instead of an ArrayList. When you remove an element from an ArrayList, all following elements have to be shifted which takes a lot of time. A LinkedList should behave better.
    Finally, instead of searching for duplicates, consider to check for duplicates when filling the list or even use a Map.
    Tobias

  • Saving linked list into oracle

    hi, i want to store a linked list in sql, and it should be like that it should grow itself , if i want to add some elements in future,
    i know i have to use jdbc, but if i can get some kind of example for that , it will be quite easier then.....any idea plzz

    Have tables like this?
    LIST table:
    LIST_ID <PK>
    ...any other fields you wish...
    LIST_ELEMENT table:
    LIST_ID <PK> <FK>
    LIST_INDEX <PK>
    ELEMENT_DATA
    ...

  • N^2 log(n) for Collections.sort() on a linked list in place?

    So, I was looking over the Java API regarding Collections.sort() on linked lists, and it says it dumps linked lists into an array so that it can call merge sort. Because, otherwise, sorting a linked list in place would lead to a complexity of O(n^2 log n) ... can someone explain how this happens?

    corlettk wrote:
    uj,
    ... there are other sorting methods for linked lists with an O(N*N) complexity.Please, what are those algorithms? I'm guesing they're variants off insertion sort, coz an insertion is O(1) in a linked list [and expensive in array]... Am I warm?You don't have to change the structure of a linked list to sort it. You can use an ordinary Bubblesort. (The list is repeatedly scanned. In each scan adjacent elements are compared and if they're in wrong order they're swapped. When one scan of the list passes without any swaps the list is sorted). This is an O(N*N) algoritm.
    What I mean is it's possible to sort a list with O(N*N) complexity. It doesn't have to be O(N*N*logN) as the Java documentation kind of suggests. In fact I wouldn't be surprised if there were special O(N*logN) algoritms available also for lists but I don't know really. In any case Java uses none of them.

  • Array of Linked List Help

    I am fairly new to Java, and Linked Lists. Can you tell me how I can fix my code? Why does my code print infinite "3" s. That is all I am trying to do is create a linked list and put that linked list into index 2 of the array. In the loop, I am setting up a whole bunch on null Node's, is it even possible to link all these nodes together in that same loop? If something does not make sense, I will try to elaborate. I will eventually impliment an insert method in the Node class, are there any pointers on how to implement it? What are the special cases I need to be looking for when implementing the insert method?
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package testlinkedlist;
    * @author Ben
    public class Main {
         * @param args the command line arguments
        public static Node l;
        public static Node p = new Node();
        public static Node Front;
        public static void main(String[] args) {
            Node[] anArray = new Node[4];
            for(int i = 0; i < 4; i++){
                anArray[i] = new Node();
                l = new Node(i);
                l.setLink(l);
            anArray[2] = l;         
            while(anArray[2] != null){
                System.out.println(anArray[2].dataInNode());
                anArray[2] = anArray[2].next;
    }

    l = new Node(i);
    l.setLink(l);The node l is created in line one, in line two a link is created from l to l. In other words here is the presence of your infinite loop which is magnified in the following piece of code:
    anArray[2] = l;         
    while(anArray[2] != null){
      System.out.println(anArray[2].dataInNode());
      anArray[2] = anArray[2].next;
    }Mel

  • 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){
    }

  • Question about using for-loop to generate array from DAQmx. Thanks!

    I have a laser system with a frequency of 1kHz, I am using this 1kHz signal to trigger the DAQmx and get the data from a photodetector, e.g. I will get 1000 data points during 1 second from DAQmx, but I need to separate this 1000 data points into the even and odd list, which is two list of 500 data points, e.g.. The 1st, 3rd, ... 99th data is one array, the 2nd, 4th,... 10th data is another array, then I will do further calculations based on these two arrays.
    To seperate the even and odd data, the only way I can find is put these 1000 points into an array and then seperate them afterwards.
    Can I do things like this pic?
    I don't know the speed of the for loop, because the 1kHz trigger is always there, once it is triggered, the DAQmx read will give a data point, if the speed of the for-loop( the time from the end of a loop to the beginning of the next loop) is slower than the 1kHz trigger, then the for-loop will miss data point, then the ordering of the 1000 points in 1 second will be changed.
    Or I need to put everything, e.g. AI Voltage, Trigger, sample clock, into the for-loop and then return a Y? Thanks! 

    Clarification:
    The VI you have posted will work as following:
    1) The task will read 2 analog inputs (ai0, ai3).
    2) The acquisition starts, oncece digital signal (trigger) is detected on PFI0
    3) The sampling rate will be as specified in "rate" control - it is continuous analog input acquisition, which means that after trigger is received (point 2), the board will start to generate hardware clock with frequency you specify as "rate"
    4) with each rising edge of that hardware clock, the measurement is taken, and stored into buffer of driver.
    5) DAQmx read will try to read "number of samples per channel" number of samples each time is called - and if there is not enough measurement stored in buffer (step 4), then DAQmx read will wait until DAQ card will measure reaquested number of samples (or timeout occurs before requested number of samples has been acquired)
    6) DAQmx read will be then called 1000 times - so totaly you will read 1000 * "number of samples per channel"  number of samples.
    You do not have to be worried about speed of the loop. In fact, if you need to read just 1000 samples, with 1kS/s, then you can remove for loop and you can change measurement mode from continuous to finite samples, and specify number of samples to read to be 1000. You will read them all properly. I recomend you to read User Manual for your DAQ device - lets say M Series User Manual.
    I hope it is clear now.
    regards,
    stefo

  • 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.

  • State Diagram inside For Loop

    I created a fairly involved for-loop with a flat sequence inside of it.  The sequence had about four events that occured, and since it was kind of ugly, I thought I'd try the State Diagram Toolkit to replace the majority of the code.  When I selected state diagram from the pallete, I was outside my for-loop.  I drew up the various states/transitions, then realized that all this code needed to be inside the for-loop, but LV won't let me place state diagram-generated code inside the for-loop.  I select everything related to the state diagram, but when I drag into the for-loop, only the comments come inside.  I even tried generating a new for-loop and placing the state code inside.  No luck. Any thoughts?

    "Any thoughts?"
    Yes but not any that will help.
    1) Just modify your SD so that the exit loops back to the start while there are still things to do. Forget the outer For loop.
    2) THe observations you reported are correct. When I first discovered these limitiations I said "That sucks!". Since then I have learned a bit and have grown to love the SDE.
    The SDE is JUST (note: "just" is a four letter word around here ) a LV application that ofers a very limited GUI consisting of a picture control that then scripts (see LAVA Scripting Forum for info on scripting) your SD for you. SCripting LV code is no easy task. My experiments with scripting has shown that I have to keep a database of the contents of the LV diagram my code is developing to keep track of what is where. Well it turns out that the structure of a LV diagram is a lot like the structure of a FP in that you start with a "root" object either the FP or the BD. THe BD then has structures on it, like seq's loops etc with unlited nesting possible.
    Now the SD created by the SDE is really just a fancy while loop with an case structure and code to support the driving enum. In order for you to be able to edit the SD the SDE needs to know what is htere already so it can show the diagram. It "KNOWS" by looking at its internal DB (I believe is stored inside of VI along with the enum.ctl) of the SD. To keep the DB updated, the SDE must be used to manipulate the SD.
    Stop rambling and guessing and get to the point!
    Moving the SD is just not supported by the SDE so it can not be done. To do so would require the SDE be able to "look" at the diagram, and repeat all of its work in the new location in the diagram.
    BTW: Thank you for trying out and asking about the SDE. the more talking we do on this subject, the sooner the SDE will be updated.
    My SDE wishlist (partial)
    Add comments to diagram from SDE screen.
    Add data structures to SD (shift registers) from SDE screen.
    Add "un-do".
    Select multiple objects on SDE screen and move or allign.
    Select multiple objects on SDE screen and do "create sub-State-Diagram".
    Allow watching more than one SDE in execution highlighting at the same time.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Why are date and time strings lost when indexing an array in a for loop

    Hi, 
    I have an application where i'm reformatting data from a spreadsheet for graphical display on a LabVIEW dashboard.
    the original spreadsheet has date and time values in separate columns, and i'm merging them and converting to a timestamp value.  But something's not working.  Does anyone know why the string value is lost when the array indexes into this for loop?
    Attachments:
    failed array index.png ‏142 KB

    Can you attach your VI with some typical values? (e.g. create in indicator on the 2D array, run your VI, then turn the indicator (now containing data) into a diagram constant). Place the FOR loop related code and that diagram constant into a new VI and attach it here.
    How many times does the FOR loop run? Could it be that the last element of each 1D array is an empty string? (unless you put a wait inside the FOR loop, you'll never see the other elements in the probe)
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for