add method of LinkedSortList

Posted on 2006-04-12
Last Modified: 2006-11-18
   I'm trying to write an add method for a LinkedSortList class. Can someone explain the algorithm (don't write the code) step-by-step for the add method? The spec is to add an element without changing the order of the list (keeps it in order). The structure to use is linear nodes. I would really appreciate it. Thanks!
Question by:azcalv408
    1 Comment
    LVL 2

    Accepted Solution

    You have the list as follows:

    You have to add new element "W".
    Begin to iterate elements and find position where new element is in relation like:


    then you set pointers like:

    PREVIOUS .next = ADDED
    ADDED.previous = PREVIOUS = NEXT
    NEXT.previous = ADDED

    so you begin to iterate elements of you current array and you find out that:

    A,B - no action
    B,D - no action
    D,Z - here you take the action: = W
    W.previous = D = Z
    Z.previous = W

    then you have structure:



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Title # Comments Views Activity
    Using java code in .Net/c#: namespace issue 3 38
    parentbit challenge 3 37
    HashMap Vs TreeMap 12 32
    Unable to start eclipse ? 17 45
    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
    This video teaches viewers about errors in exception handling.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now