Sorting singly linked list with minimum time complexity

Hi ...
anyone could tell me how can i sort singly linked list with minimum time complexity .... ????
Regards...

By MergeSort or QuickSort O(n log n). But then you
have to first extract the objects in the list,sort
them, then rebuild the list. But it will still bealot
faster than by keeping the list linked.Technically, I believe insertion sort is marginally
faster for small n ( <20 or so).Woohoo! So for 20 out of the possible 2147483648 array
sizes Insetion is faster!
Unfortunately, checking for that case probably wastes
all the time you get from using the faster sort...
That would depend on the actual distribution off array sizes. So it's an engineering decision.
Sylvia.

Similar Messages

  • Single Linked List

    Hi Guys,
    I am trying to create a single linked list with one node pointing to the other. Then I have to create a method that displays the contents of the nodes. This method must take the head of the linked list as a parameter.
    I have created a class called node to store the data of each node created: This is the class;
    public class Node {
        String data;
        Node next;
        public Node(String data) {
            setData(data);
            setNext(null);
        } // Constructor
        public void setData(String data) {
            this.data = data;
        public void setNext(Node next) {
            this.next = next;
        public String getData() {
            return data;
        public Node getNext() {
            return next;
        public String toString() {
            if(data == null)
                return "Node: null";
                else
                return "Node: " + data.toString();
    }The second class is LinkedList which initialises each node and creates the linked list.
    public class LinkedList {
        private Node head;
        public LinkedList() {
            setHead(null);
        } // constructor
        private void setHead(Node head) {
            this.head = head;
        } // setHead
        private Node getHead() {
             return head;
        } // getHead
        public void add(String data) {
            if(getHead() == null){
                Node temp = new Node(data);
                temp.setNext(getHead());
                setHead(temp);
            else
                add(getHead(), data);
        } // add
        public static void main (String args[]){
            Node n1 = new Node();
            n1.setData("Jane");
            if (getHead() == null){
                setHead(n1);
            }else{
            System.out.println ("No initialisation of Linked List");
            n1.setNext(n2);
            Node n2 = new Node();
            n2.setNext(n3);
            n2.setData("Maria");
            Node n3 = new Node();
            n3.setNext(n4);
            n3.setData("Paul");
            Node n4 = new Node();
            n4.setData("Charlene");
    }Am I on the right track? And how can I create the method to display all the nodes which takes the head of the list as a parameter only?
    Thanks a lot

    doobybug wrote:
    The code I posted compiled.Then pls fix me errors:
    LinkedList.java:24: add(java.lang.String) in LinkedList cannot be applied to (Node,java.lang.String)
                add(getHead(), data);
                ^
    LinkedList.java:29: cannot find symbol
    symbol  : constructor Node()
    location: class Node
            Node n1 = new Node();
                      ^
    LinkedList.java:31: non-static method getHead() cannot be referenced from a static context
            if (getHead() == null){
                ^
    LinkedList.java:32: non-static method setHead(Node) cannot be referenced from a static context
                setHead(n1);
                ^
    LinkedList.java:35: cannot find symbol
    symbol  : variable n2
    location: class LinkedList
                n1.setNext(n2);
                           ^
    LinkedList.java:36: cannot find symbol
    symbol  : constructor Node()
    location: class Node
                Node n2 = new Node();
                          ^
    \LinkedList.java:37: cannot find symbol
    symbol  : variable n3
    location: class LinkedList
                n2.setNext(n3);
                           ^
    LinkedList.java:39: cannot find symbol
    symbol  : constructor Node()
    location: class Node
                Node n3 = new Node();
                          ^
    LinkedList.java:40: cannot find symbol
    symbol  : variable n4
    location: class LinkedList
                n3.setNext(n4);
                           ^
    LinkedList.java:42: cannot find symbol
    symbol  : constructor Node()
    location: class Node
                Node n4 = new Node();
                          ^
    10 errors

  • Why LinkedList uses doubly linked list and not single link list

    Hi,
    Please help me to understand the concept behind java using doubly linked list for LinkedList and not single link list?
    Edited by: user4933866 on Jun 26, 2012 11:22 AM
    Edited by: user4933866 on Jun 26, 2012 11:25 AM
    Edited by: EJP on 27/06/2012 08:50: corrected title to agree with question

    EJP wrote:
    Could you help me with one real world use case where we need to traverse linklist and arraylist in backward direction other than printing the linklist or arraylist in reverse order. One example is that you might want to use it as a stack. For a very large (+very+ large) stack it would out-perform the Vector-based Stack in the API.The first thing that pops into my head is an undo/redo function for a text editor. Each edit action is dumped onto such a stack. Each time you hit CTRL+Z to undo an action you go back in the stack. Each time you hit CTRL+Y to redo the action you go forward again.

  • A simple list with seven time buckets starting from the date report is run.

    Hi All,
    I am new to ABAP.Recently i have planned to write a progam which will help in planning the delivery of scheduled items.For a given sales Org. it will display all the undelivered,delivered items in a simple list and sort them with delivery dates.it will also provide a summary report at material group.For that i have used selection screen(LIKP-VKORG-Obligatory).when i enter VKORG Details i should get all the delivery docs for which delivery is not done or partially done.For this i have taken one more table LIPS
    (LIPS-MATKL,LIPS-MATNR,LIPS-VBELN,LIPS-POSNR,LIPS-WERKS,LIPS-LFIMG,LIPS-MEINS) for tables LIKP and LIPS VBELN is the key field.when i enter VKORG Data in the selection screen ,how can i get the data from LIPS Table.Please explain?
    Also report should be simple list with seven time buckets starting from the date when the report is run.The amount of quantity to be delivered should be displayed under appropriate bucket i.e within the bucket where its delivery date falls in.for ex:If the report is run on Tuesday 15th march 2010 then the start date 1 should be starting date of the week which is Monday 14th March.
    The report will be summarized at Material Group and Material Number.
    Appreciate your help
    Thanks and Regards,
    Shakeer Hussain

    Sorry, sounds too much like a complete requirement you want done for you by the community.
    Please work on it yourself and search for available information before posting specific problems only.
    Thread locked.
    Thomas

  • [svn:bz-trunk] 18926: bug fix BLZ-570 Double linked list with lot of objects result in BlazeDS Error deserializing error  : StackOverflowError

    Revision: 18926
    Revision: 18926
    Author:   [email protected]
    Date:     2010-12-01 14:07:19 -0800 (Wed, 01 Dec 2010)
    Log Message:
    bug fix BLZ-570 Double linked list with lot of objects result in BlazeDS Error deserializing error : StackOverflowError
    We put hard limit to the max object nest level to prevent StackOverFlowError. the default max object nest level is 1024 and it can be configured in the endpoint/serialziation section in service-config.xml.
    This needs documentation.
    Checkintests pass
    Ticket Links:
        http://bugs.adobe.com/jira/browse/BLZ-570
    Modified Paths:
        blazeds/trunk/modules/common/src/flex/messaging/errors.properties
        blazeds/trunk/modules/core/src/flex/messaging/endpoints/AbstractEndpoint.java
        blazeds/trunk/modules/core/src/flex/messaging/io/SerializationContext.java
        blazeds/trunk/modules/core/src/flex/messaging/io/amf/Amf0Input.java
        blazeds/trunk/modules/core/src/flex/messaging/io/amf/Amf3Input.java
        blazeds/trunk/modules/core/src/flex/messaging/io/amf/AmfIO.java

  • [svn:bz-4.0.0_fixes] 20451: backporting bug fix BLZ-570/ BLZ-620 Double linked list with lot of objects result in BlazeDS Error deserializing error  : StackOverflowError  We put hard limit to the max object nest level to prevent StackOverFlowError .

    Revision: 20451
    Revision: 20451
    Author:   [email protected]
    Date:     2011-02-24 08:33:31 -0800 (Thu, 24 Feb 2011)
    Log Message:
    backporting bug fix BLZ-570/BLZ-620 Double linked list with lot of objects result in BlazeDS Error deserializing error : StackOverflowError  We put hard limit to the max object nest level to prevent StackOverFlowError. the default max object nest level is 1024 and it can be configured in the endpoint/serialziation section in service-config.xml. This needs documentation.  Checkintests pass
    Ticket Links:
        http://bugs.adobe.com/jira/browse/BLZ-570
        http://bugs.adobe.com/jira/browse/BLZ-620
    Modified Paths:
        blazeds/branches/4.0.0_fixes/modules/common/src/flex/messaging/errors.properties
        blazeds/branches/4.0.0_fixes/modules/core/src/flex/messaging/endpoints/AbstractEndpoint.j ava
        blazeds/branches/4.0.0_fixes/modules/core/src/flex/messaging/io/SerializationContext.java
        blazeds/branches/4.0.0_fixes/modules/core/src/flex/messaging/io/amf/Amf0Input.java
        blazeds/branches/4.0.0_fixes/modules/core/src/flex/messaging/io/amf/Amf3Input.java
        blazeds/branches/4.0.0_fixes/modules/core/src/flex/messaging/io/amf/AmfIO.java

    Dear Pallavi,
    Very useful post!
    I am looking for similar accelerators for
    Software Inventory Accelerator
    Hardware Inventory Accelerator
    Interfaces Inventory
    Customization Assessment Accelerator
    Sizing Tool
    Which helps us to come up with the relevant Bill of Matetials for every area mentioned above, and the ones which I dont know...
    Request help on such accelerators... Any clues?
    Any reply, help is highly appreciated.
    Regards
    Manish Madhav

  • [svn:bz-3.x] 20443: back porting bug fix BLZ-570/ BLZ-620 Double linked list with lot of objects result in BlazeDS Error deserializing error  : StackOverflowError  We put hard limit to the max object nest level to prevent StackOverFlowError .

    Revision: 20443
    Revision: 20443
    Author:   [email protected]
    Date:     2011-02-23 21:19:22 -0800 (Wed, 23 Feb 2011)
    Log Message:
    back porting bug fix BLZ-570/BLZ-620 Double linked list with lot of objects result in BlazeDS Error deserializing error : StackOverflowError  We put hard limit to the max object nest level to prevent StackOverFlowError. the default max object nest level is 1024 and it can be configured in the endpoint/serialziation section in service-config.xml. This needs documentation.  Checkintests pass
    Ticket Links:
        http://bugs.adobe.com/jira/browse/BLZ-570
        http://bugs.adobe.com/jira/browse/BLZ-620
    Modified Paths:
        blazeds/branches/3.x/modules/common/src/java/flex/messaging/errors.properties
        blazeds/branches/3.x/modules/core/src/java/flex/messaging/endpoints/AbstractEndpoint.java
        blazeds/branches/3.x/modules/core/src/java/flex/messaging/io/SerializationContext.java
        blazeds/branches/3.x/modules/core/src/java/flex/messaging/io/amf/Amf0Input.java
        blazeds/branches/3.x/modules/core/src/java/flex/messaging/io/amf/Amf3Input.java
        blazeds/branches/3.x/modules/core/src/java/flex/messaging/io/amf/AmfIO.java

  • Sorting into Linked Lists

    What I want to do is make a Linked List that has options.
    1. Allows Duplicates & Non Sorted
    2. Allows Duplicates & Sorted Alphabetically
    3. Allows Duplicates & Sorted Reverse Alphabetically
    4. Doesn't Allow Duplicates & Non Sorted
    5. Doesn't Allow Duplicates & Sorted Alphabetically
    6. Doesn't Allow Duplicates & Sorted Reverse Alphabetically
    sortOrder and duplicate are my global variables controlling those two options.
    Reverse alphabetical and alphabetical will just be opposites.
    I've got the duplicates or non duplicates part working as well as non-sorted part.
        public void add(Object obj){
        // post: appends the specified element to the end of this list.
            Node temp = new Node(obj);
            Node current = head;
            Node hold = head;
            // starting at the head node, crawl to the end of the list
            //Takes care of duplicates
            if (!duplicate) {
                if (lookup(obj)) {
                return;
            System.out.println("OBJECT: " + obj.toString()); // See what I am passing
            if (sortOrder==0) { //non-sorted
                while(current.getNextNode() != null) {
                    current = current.getNextNode();
            // the last node's "next" reference set to our new node
                current.setNext(temp);
            if (sortOrder<0) { // decreasing
                while(current.getNextNode() != null) {
                    current = current.getNextNode();
                    System.out.println("CURRENT: " + current.getData().toString()); //Where I am sitting in the list
                    System.out.println("IF STATEMENT: "+ obj.toString().compareTo(current.getData().toString())); // Where the object sits alphabetically to current
                        if(obj.toString().compareTo(current.getData().toString())>0) {
                            hold.setNext(temp);
                            temp.setNext(current);
                            System.out.println("Object is closer to z Alphabetically");
                            return;
            // the last node's "next" reference set to our new node
    /*    if (sortOrder>0) { // increasing
            while(current.getNextNode() != null) {
                current = current.getNextNode();
                System.out.println("CURRENT: " + current.getData().toString());
                if (obj.toString().compareTo(current.getData().toString())<0){
        // the last node's "next" reference set to our new node
                    temp.setNext(current.getNextNode());
                    current.setNext(temp);
                    return;
    }

    humer015 wrote:
    What I want to do is make a Linked List that has options.
    1. Allows Duplicates & Non Sorted
    2. Allows Duplicates & Sorted Alphabetically
    3. Allows Duplicates & Sorted Reverse Alphabetically
    4. Doesn't Allow Duplicates & Non Sorted
    5. Doesn't Allow Duplicates & Sorted Alphabetically
    6. Doesn't Allow Duplicates & Sorted Reverse AlphabeticallyI'd set up 4 separate collections with the correct characteristics (6 if you think you need to keep the 'reverse order' versions separately). Remember, having 6 lists doesn't mean 6 sets of data; just 6 arrangements.
    sortOrder and duplicate are my global variables controlling those two options.Sounds like an implementation decision before its time to me, unless it's dictated by programs that you have no control over. Get your lists working and then decide how you want to implement your system parameters.
    HIH
    Winston

  • Sorting My Linked List

    Alright, here's the problem. I have my linked list, either imported from a text file or inputted by the user. Now, I need to sort it by the date and the time strings... Yet, every time I do I get an NullPointException. Can anyone help? Here's my code for the list:
    public class ListReferenceBased implements ListInterface{
         //references to the linked list items
         private Node head;
         private int numItems; //number of items that exist in list
         //Default Constructor
         //sets both items to null
         public ListReferenceBased(){
              numItems = 0;
              head = null;
         //if the numItems in the list is empty
         //returns true.
         public boolean isEmpty(){     
              return numItems == 0;
         // returns numItems, aka the size of the list
         public int size(){
              return numItems;
         //finds a node by setting a node to the 'head'
         // and loops through to the index 'resetting'
         // curr to the 'next' node.
         private Node find(int index){
              Node curr = head;
              for( int skip = 1; skip < index; skip++){
                   curr = curr.getNext();
              return curr;
         public Object get(int index)
              throws ListIndexOutOfBoundsException{
              //catches if list does not reach the index given
              //loops through the index
              if(index >= 1 && index <= numItems){
              //sets curr to the index through find()
              Node curr = find(index);
              //sets dataitem to the current node
              Object dataItem = curr.getItem();
              return dataItem;
              }else{
              throw new ListIndexOutOfBoundsException("The List index is out of bounds on get");
         public void add(int index, Object item)
              throws ListIndexOutOfBoundsException{
              //checks to make sure there are no nodes yet
              //if there are inserts them in the list
              //by moving
              if(index >=1&& index<= numItems+1){
                   if(index==1){
                        // if no list exists
                        //creates a new node and sets it to head
                        Node newNode = new Node(item, head);
                        head = newNode;
                   }else{
                             //inserts the node at the index
                             //by finding it first
                             Node prev = find(index-1);
                   //creates a new node by placing the Object item
                   //and the 'new prev' node into a node
                   //'deleting' the old 'bonds'
                   Node newNode = new Node(item, prev.getNext());
                   rev.setNext(newNode);
                        //increments number of items in list
                        numItems++;
              }else{     
                        throw new ListIndexOutOfBoundsException("List index out of bounds");
         public void remove(int index)
              throws ListIndexOutOfBoundsException{
              //catches the list if it doesn't exist
              //checks to make sure list exists
              if(index>=1&& index<= numItems){
                   //if only the head exists
                   //calls next node else moves
                   //the node away and moves the prev
                   //on up.
                   if(index==1){
                        head = head.getNext();
                   }else{
                        Node prev = find(index-1);
                        Node curr = prev.getNext();
                        prev.setNext(curr.getNext());
                   //decreases the number of items in list
                   numItems--;
              }else{
         throw new ListIndexOutOfBoundsException("List index out of bounds");
         //sets the numItem to null telling the list it
         //does not exist
         public void removeAll(){
              head = null;
              numItems=0;
              

    Yeah, unfortunately, I had to design my own linked list for my assignment (that's taken almost 40+ hours). So, now every alogrithm I've tried to write seems to give me a null pointer, for example this one
    public void sort(){
              //loop through all existing nodes
              for(Node curr = head; curr != null; curr = curr.getNext()){
                   //parse the string of the current node
                   //to a string value
                   Node current = curr.getNext();
                   Node next = current.getNext();
                   Node temp;
                   String thisline = current.getItem().toString();
                   System.out.println(thisline);
                   StringTokenizer parser = new StringTokenizer ( thisline, "\t" );
                   String thisdate = parser.nextToken();
                   String thistime = parser.nextToken();
                   String thisline2 = next.getItem().toString();
                   System.out.println(thisline2);
                   StringTokenizer parser2 = new StringTokenizer ( thisline2, "\t" );
                   String thisdate2 = parser.nextToken();
                   String thistime2 = parser.nextToken();
                   //compares the dates of next in list
                   if(thisdate.compareTo(thisdate2)==1){
                        next.setNext(current);
                        current.setNext(next.getNext());
                        printList();
                        //if dates equal, compare the times
                   //if equal move to new position
                        //delete old position
    }Pretty much I believe moving the positions is causing the problems after the first run around. Any suggestions?

  • Bubble Sort in Linked List

    so, everything works through the first iteration (don't know if this is an appropriate term for linked lists, but we just learned arrays) but then it stops. I thought that telling it to continue until position.next != null and increasing the position after every iteration would work but I think I have coded something incorrectly / am not taking something into consideration. I would be greatly obliged if you can offer any advice!
    Thanks,
    Hunter
           public void bubbleSort()
             Node current, a, previous, position;
             position = new Node(0);
             position.next = head;
             head = position;
             while (position.next != null)
             {  current = position.next;
                        previous = position;
                a = current.next;
                while(a != null)
                   if (a.getVal() < current.getVal())
                      Node temp = a.next;
                      a.next = previous.next;
                      previous.next = current.next;
                      current.next = temp;
                                  previous = a;
                                  a = temp;
                    else
                                  a = a.next;
                      current = current.next;
                                  previous = previous.next;
                 position = position.next;
             head = head.next;

    First, thanks for the response! I have been trying println statements and really don't understand the problem. I have also gone through line-by-line and drawn out what I think is supposed to happen and still can't seem to fully figure out what I am doing wrong. Here is the full code, this might help with the 'definition of my list'.
        public class LinkedList
          public Node head;
           public LinkedList(int length)
             head = null;
             for (int i = 0; i < length; i ++)
                insert(i);
           public LinkedList()
             head = null;
           public void clear()
             head = null;
           public void insert(int n)
             Node current = new Node(n);
             current.next = head;
             head = current;
           public void insert(Node n, int index)
             Node previous, current;
             Node nnode = new Node(-10);
             nnode.next = head;
             previous = nnode;
             current = head;
             while (current != null && index > 0)
                current = current.next;
                previous = previous.next;
                index --;
             if (previous == nnode)
                n.next = head;
                head = n;
             else
                previous.next = n;
                n.next = current;
       //Delete the node at the zero-based index.
           public void delete(int index)
             int current;
             Node currentnode = head;
             for (current = index; current > 1; current --)
                currentnode = currentnode.next;
             if (currentnode == head)
                head = head.next;
             else
                currentnode.next = currentnode.next.next;
           public Node getNode(int index)
             Node nnode = new Node(-10);
             nnode.next = head;
             Node current = head;
             while(current.next != null && index > 0)
             {     current = current.next;
                index --;
             return current;
           public int getVal(int index)
             int current;
             Node currentnode = head;
             for (current = index; current > 0; current --)
                currentnode = currentnode.next;
          //currentnode should point to the node whose value we want.
             return currentnode.getVal();
           public void print()
             System.out.println();
             head.print();
           private void swap(Node pa, Node a, Node pb, Node b)
             Node temp = b.next;
             pa.next = b;
             if (a.next != b)
                b.next = a.next;
                pb.next = a;
             else
                b.next = a;
             a.next = temp;
           public void selectionSort()
             Node current, a, previous, position;
             position = new Node(0);
             position.next = head;
             head = position;
             while (position.next  != null)
                current = previous = position.next;
                a = position.next;
                while(a != null)
                   if (a.getVal() < current.getVal())
                      current = a;
                      while(previous.next != current)
                         previous = previous.next;
                   a = a.next;
                if (current != previous)
                   Node t = position.next;
                   swap(position, t, previous, current);
             //System.out.println("****************");
             //head.print();
                position = position.next;
             head = head.next; //to lose the initial node.
          //System.out.println("end of sorting, head.print is");
          //head.print();
           public void bubbleSort()
             Node current, a, previous, position;
             position = new Node(0);
             position.next = head;
             head = position;
             while (position.next != null)
             {  current = position.next;
              previous = position;
                a = current.next;
                while(a != null)
                   if (a.getVal() < current.getVal())
                      Node temp = a.next;
                      a.next = previous.next;
                      previous.next = current.next;
                      current.next = temp;
         previous = a;
         a = temp;
                    else
                    a = a.next;
                    current = current.next;
         previous = previous.next;
                 position = position.next;
             head = head.next;
          }

  • Selection Sort using Linked Lists

    As the subject says, I'm trying to implement a selection sort method on a linked list structure. I've already created a bubble sort, but I can't seem to get this method to work correctly. The Node and LinkedList classes were written by me, and I know they work correctly (because of the other methods work right).
    public void selectionSort(LinkedList list) {
            int iterationsINNER = 1, iterationsOUTER = 1, swaps = 0, comparisons = 1;
            if(list.isEmpty())
                System.out.println("List is currently empty.");
            else if (list.size() == 1)
                System.out.println("List is already sorted.");
            else {
                Node pointer = list.getFirst();
                Node current;
                boolean exchangeMade;
                while (pointer.getNext().getNext() != null) {
                    current = pointer;
                    exchangeMade = false;
                    iterationsOUTER++;
                    while (current.getNext() != null && !exchangeMade) {
                        if(current.getNext().getData() < pointer.getData()) {
                            int temp = pointer.getData();
                            pointer.setData(current.getNext().getData());
                            current.getNext().setData(temp);
                            exchangeMade = true;
                            iterationsINNER++;
                            swaps++;
                            comparisons++;
                        current = current.getNext();
                    pointer = pointer.getNext();
              //  System.out.println("Comparisons: " + comparisons + " \nSwaps: " + swaps + " \nIterations: " + iterationsINNER+iterationsOUTER);
        }For instance, if I run this bit of code...
    LinkedList list = new LinkedList();
            list.insert(5);
            list.insert(29);
            list.insert(2);
            list.insert(1);
            list.insert(13);
            list.insert(8);
            list.insert(30);
            list.insert(3);
            sort.selectionSort(list);
            list.print();The output is...
    1
    8
    13
    3
    2
    29
    30
    5
    Anyone have any idea what is going wrong, or is anymore information needed?
    PS: I also need to create a insertion sort method with this, and I've been told I need to reverse the list for the insertion sort to work correctly. Any tips on how to implement this method too? :)

    I've changed it up a bit, and it works, but is this still a bubble sort? I've tried uncommenting that section that keeps track of the iterations and such, but I know they can't be right. Does this look correct? I basically just removed that boolean check...
    public void selectionSort(LinkedList list) {
            int iterationsINNER = 1, iterationsOUTER = 1, swaps = 0, comparisons = 1;
            if(list.isEmpty())
                System.out.println("List is currently empty.");
            else if (list.size() == 1)
                System.out.println("List is already sorted.");
            else {
                Node pointer = list.getFirst();
                Node current;
                while (pointer.getNext() != null) {
                    current = pointer;
                    iterationsOUTER++;
                    while (current.getNext() != null) {
                        comparisons++;
                        if(current.getNext().getData() < pointer.getData()) {
                            int temp = pointer.getData();
                            pointer.setData(current.getNext().getData());
                            current.getNext().setData(temp);
                            iterationsINNER++;
                            swaps++;
                        current = current.getNext();
                    pointer = pointer.getNext();
                System.out.println("Comparisons: " + comparisons + " \nSwaps: " + swaps + " \nIterations: " + iterationsINNER+iterationsOUTER);
        }And no, I tried and I don't get a NullPointerException if I have a list of 2.
    Edited by: birdboy30 on Dec 3, 2007 7:23 PM

  • Linked Lists with polynomials

    Hello there, i have a problem with my project for this java class, it asks to store polynomials as linked lists of terms (it countains coefficient and power of x) i also need to multiply them, do u suggest that i make a Polynomial object that has coeff and power as parameters and then transmit them to the add method of the ListIterator interface? but the add function takes only an object?
    for multiplying, how do i get, for exmaple the first 2 terms of 2 polynomials p and f? and then create another linked list to store the new plynomial?
    i will be grateful for any help,
    thanks

    You're on the right track, from what I can figure. Your idea of creating an object, say PolyTerm to hold the coefficient and degree of the term will work wonderfully.
    All you need now is to figure out how to multiply, right? Well, basically a polynomial multiplication is poly1term1 X poly2term1 + poly1term1 X poly2term2, etc, etc.
    So, you need two iterators, one to loop through each polynomial, getting the PolyTerm object at the relevant index, perform you multiplication, and add it to a third list that you've initialized.

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

  • Linking C++ with Real-Time

    I have created a dll using Microsoft VC++ 9.0 (2008)  to  be linked in real-time. Unfortunately when I try to check this dll using LabviewRT DLL checker I am getting a message that "DLL is bad. Check the imports." and the bad imports are from msvcr90.dll.....My dll is working perfectly in the windows environment but the DLLchecker says that it is bad. I have tried using the example codes from the tutorials for creating such "dlls using Microsoft VC++ 5.0 / 6.0", but those examples seem to have the same problems as well with the latest VC++ version. Unfortunately I don't have these old version VC++ compilers. Is there any other way that I can create a c++ dll and link it to real-time?
    Thansk for your help in this regard.

    National Instruments currently does not support Visual C++ 9.0.  However, you still might be able to use this compiler by taking a few extra steps. You will need to include the runtime (mscvr90.dll) and all necessary pieces statically in the DLL as support files passed to the RT target. Please be aware that this may result in a very large DLL.  Let me know if you have anymore questions, thanks!

  • Appending a singly linked list

    I need to append a linkList ie- add another node onto the end of a linked list. I am rather new at this and would appreciate the help, thnaks.

    Refer to java docs java.util.LinkedList class.
    If you dont have the java docs download it from the site.
    Advice: You should always have java docs at hand
    Ironluca

Maybe you are looking for

  • To load data from a cube in SCM(APO) system to a cube in BI system.

    Experts,      Please let me know whether it is possible to load data from a cube in SCM(APO) system to a cube in BI system.If so explain the steps to perform. Thanks, Meera

  • I pre ordered a movie on iPad but I don't know how to download it?

    I pre-ordered a movie on iTunes and when It came out I got an email with a link saying to download it but when I click on it it just goes to iTunes I don't know what to do from there help me please?.

  • Connecting my iPad to a smartboard

    I work in a school & our smart boards are operated through apple mini macs, on my personal iPad I have interactive books that I would like to share with my class but having trouble finding out how to connect.

  • No nested folders in Saved Locations?

    I love the Saved Locations feature in the Map module.  I imagine I will end up with large amounts of these over time, but currently the folder structure seems to be limited to root level folders.  Would it be possible to upgrade this to allow nested

  • Preloader code

    I'm using the code from this tutorial for a preloader.  Though I am not using a dynamic text field like the tutorial says. I took the line referring to the dynamic text field out of the code, but it's still not working? The animation has 2 frames wit