Alphabetically ordering a Linked List

Would anyone please be able to give me help in ordering a linked list alphabetically. I'm new to java so please be gentle.
Many thanks in advance.

I've just tried that but it gave me errors on trying to compile it:
.\List.java:91: Incompatible type for method. Explicit cast needed to convert List to java.util.List.
     Collections.sort(leftList);
     ^
.\List.java:92: Incompatible type for method. Explicit cast needed to convert List to java.util.List.
     Collections.sort(rightList);
     ^
2 errors
I'll post my coding below to see if you can help me out. Thanks a lot.
import java.util.LinkedList;
import java.util.Collections;
class ListNode {
// package access data so class List can access it directly
char data;
ListNode next;
// Constructor: Create a ListNode that refers to Object o.
ListNode( char c ) { this( c, null ); }
// Constructor: Create a ListNode that refers to Object o and
// to the next ListNode in the List.
ListNode( char c, ListNode nextNode )
data = c; // this node refers to Object o
next = nextNode; // set next to refer to next
// Return a reference to the Object in this node
char getChar() { return data; }
// Return the next node
ListNode getNext() { return next; }
// Class List definition
public class List {
private ListNode firstNode, current;
private ListNode lastNode;
private String name; // String like "list" used in printing
// Constructor: Construct an empty List with s as the name
public List( String s )
name = s;
firstNode = lastNode = null;
// Constructor: Construct an empty List with
// "list" as the name
public List() { this( "list" ); }
public synchronized boolean isEmpty()
{ return firstNode == null; }
public synchronized void insertAtBack( char insertItem )
if ( isEmpty() )
firstNode = lastNode = new ListNode( insertItem );
else
lastNode = lastNode.next = new ListNode( insertItem );
print();
// System.out.println(insertItem);
     // public char getText(){
     // return current.data;
// Output the List contents
public synchronized void print()
     current = firstNode;
while ( current != null ) {
System.out.print(current.data);
current = current.next;
System.out.println( "\n" );
// method to split the linked list
public synchronized void splitList(){
          System.out.println("splitList");
          ListNode present = firstNode;
List leftList = new List();     // create the left list
List rightList = new List();     // create the right list
          try{
               while (present != null) {
                    leftList.insertAtBack(present.data);
                    System.out.println("left " +present.data);
                    present = present.next; // skips 1 node
                    rightList.insertAtBack(present.data);
                    System.out.println("right " +present.data);
                    present = present.next; // skips 1 node
     Collections.sort(leftList);
     Collections.sort(rightList);
          catch(NullPointerException e){

Similar Messages

  • Alphabetical order of favorites list

    I would like to place the entries in my favorites list in alphabetical order. Is there a way to do this. If not does anyone know whether it will be available in an update

    Not possible, but you can arrange contacts in your Favorites list in any order you want.
    Select Favorites, and then the Edit button at the top to Edit your Favorites list.
    This provides an option to delete a favorite - located to the left of each favorite, and an option to move/slide a favorite up or down in the list, located to the right of each favorite. Place your finger on the 3 gray lines - press and slide the chosen favorite to where you want it located in your Favorites list.
    Press Done with finished.

  • Web Page Composer - Ordering Automatic lists in Alphabetical order

    Sorry if this is in the wrong place (newbie here)
    I'm trying to order an 'Automatic list' in Alphabetical order - based on page name/title
    So within WPC I have a folder with 10 or so web pages in them. and the next level up I have a page with the 'Dynamic Content' element.
    Within the 'Additional' field of the 'Dynamic Content' element I am able to 'orderBy=modified' or 'orderBy=created' but cannot seem to do what I would think is straightforward and order alphabetically by either name or title.
    Am I missing something simple and obvious?
    Or should I actually be trying to do this by modifying the XSL Template that controls the presentation?
    Thanks in advance for any help.

    Hi Alessio,
    have a look at at this thread:
    <a href="https://www.sdn.sap.com/irj/sdn/thread?threadID=599765">Link for your error message</a>
    Or maybe it is because your WPC isn't fully configured for anonymous access.
    To configure it for anonymous access, try this:
    1. Configuration in PCD - go to Content Administration -> Portal Content-> Portal Content -> Web Page Composer -> Container iViews -> WPC
    Default Containers. All of the iViews in this location should have the
    "anonymous" authentication scheme. The next location which should be
    checked is Content Administration -> Portal Content -> Portal Content ->Web Page Composer -> iView Templates. Again all of the iViews should
    have the "anonymous" authentication scheme. The same applies to all the
    templates which reside in Content Administration -> Portal Content ->
    Portal Content -> Web Page Composer -> Page Layout Templates. Finally
    check if all the pages which reside in Content Administration -> Portal
    Content -> Portal Content -> Web Page Composer -> Page Layouts have the
    "anonymous" authentication scheme.
    2. Configuration in KM - make sure that all the pages, which should be
    displayed to an anonymous user have in their permissions the Anonymous
    Users Group.
    3. Security zones - if you go to System Administration -> Permissions ->Security Zones -> com.sap.nw.wpc -> wpc -> no_safety and you open the
    permissions of this object, the Anonymous Users group must be added in
    the list.
    If all mentioned objects have their setting as described and you still
    experience problems (e.g. you see a browser dialog window for
    authentication), the reason most probably is, that the KM is not
    configured for anonymous access. A full description of the needed steps
    is provided with note 837898.
    I think the your error message could be solved with the first link.
    But afterwards you need to perform the steps mentioned above.
    Regards,
    Marcus

  • Can firefox show bookmarks list in alphabetical order like Internet Explorer?

    I don't want to have to go to "show all bookmarks" then search for a bookmark. I want to just see the list and go down to the right one, or start typing it and go to it.

    Hi
    Easiest way to put your bookmarks in alphabetical order is to right click on a bookmark folder and you have the option to "Sort By Name".
    Alternatively, have a look at this list of bookmark related addons ([https://addons.mozilla.org/en-US/firefox/extensions/bookmarks/ link]).
    Hope this helps, please come back here if you need any further assistance.

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

  • Re: jewel case insert song list in alphabetical order

    When I print a jewel case insert with single cover option,
    the song list is shown in alphabetical order instead of the correct
    track order.
    How do I fix this?
    Is this yet another bug? I have 9.0.3 (15) installed in OS X 10.4.11.

    vinylripper wrote:
    Is this yet another bug?
    Sure sounds like it. There is no reason for it to print in an order differently than the play order.
    If you care to report the bug, here is the link: http://www.apple.com/feedback/itunesapp.html

  • Reordering shop catalogue list in alphabetical order

    where or how in Business Catalyst would i put the subcategories list in alphabetical order
    Sunglasses
    Thats the link and the categories with all the brands of glasses are on the side .... some are not in alphabetical order how do i change that .

    do you drag your songs into the removable disk folder to get them on your ipod manually?

  • Sort promoted links tiles(Tiles View) in alphabetical order.

    Hi,
    i want to sort my promoted linked list tiles in alphabetical order. OOTB there is no option to sort promoted links tiles view .Any pointers on how to do this will be really helpful.

    Hi,
    If you would like to sort it by title automatically, you would modify Tiles view aspx page in SharePoint Designer.
    Please open SharePoint Designer > All files > Lists > promoted link list > Tiles.aspx, then locate the below code:
    <Query>
    <OrderBy>
    <FieldRef Name="TileOrder" Ascending="TRUE"/>
    <FieldRef Name="Modified" Ascending="FALSE"/>
    </OrderBy>
    </Query>
    Then replace it by the code below:
    <Query>
    <OrderBy>
    <FieldRef Name="Title" Ascending="TRUE"/>
    </OrderBy>
    </Query>
    Regards,
    Rebecca Tu
    TechNet Community Support

  • When I import an album into ITunes...it puts the song list in alphabetical order.  How do I get it to import the album order?

    Any suggestions on how I can import an album without the songs going to alphabetical order?  The last few times I have imported....I cannot get the play list to come up in the album order.

    Hi there,
    I'm having the same problem as this original post but reading the reply/answer i stil have no idea what has gone wrong or how to rectify it?
    Never had a problem for years untill now.
    Any other things this could be?
    Thanks
    Paul

  • How do I get my drop down lists in alphabetical order?

    Got a new computer and installed Firefox 3.6.10. I moved over my bookmarks, etc. from the old computer. However, all of my drop-down lists are not in alphabetical order any more. And if I use one of the entries, it will sometimes move to a different order than it had been when I clicked on it. How do I get them back in alphabetical order?

    The entries for form field are in current Firefox version is the order that you add them and not ordered alphabetically.<br />
    Maybe an extension like Autofill Forms can sort them.
    I'm not using it, so you need to check that yourself.
    Autofill Forms: https://addons.mozilla.org/firefox/addon/4775
    See also http://forums.mozillazine.org/viewtopic.php?f=38&t=790815&p=8823995#p8823995

  • I can no longer organize my drop down book mark list ,from the toolbar in alphabetical order like I used to Why ?

    Used to, I could organize my drop down book mark list from the tool bar, in alphabetical order from A-Z by clicking on view, sort by, select . Now every time I add a new bookmark it goes to the bottom of my bookmark list in Unsorted bookmarks . I can go to the bookmarks and sort the menu in Alpha. order. However, when I go back and drop down the bookmark list from the tool bar, the new bookmarks are still in the Unsorted list at the bottom. The bookmark's menu may or not have them in assorted list. This occurred several updates back. Why can I no longer sort the drop down book marks list in A-Z alph. order? This is a major obstacle when trying to search for a particular bookmark that I have made in the not too distant past.

    That did solve my problem. Madperson Thank You Very Much!!!!! I'm not real literate on the mechanics of working computers even though I use them all the time. Basically I'm a point & click kinda guy and beyond that I'm pure novice! This is going to save me a lot of wasted time.
    Allen C. Geiser
    ageiser34

  • List files in Finder by file type (not just all in alphabetical order)

    Hello,
    Is there a way to list the files in Finder by type.
    By default all files and folders are listed in alphabetical order.
    I, however, would like to list the subjects by type (i.e. all folders first, then single files etc.)
    Thanks in advance...
    Power Mac 2 x 2.0 GHz   Mac OS X (10.3.9)  

    Is there a way to list the files in Finder by type.
    Sorry, I don't have my 10.3 booted at the moment, but in 10.4 in List View you would normally have a Kind column at the far right. If you click on the top of this it may sort the way you want. Also the Kind column can be moved to the left if you want.

  • Is there a way to have Finder list folders and documents in alphabetical order?

    Finder keeps changing the order of folders and documents.  Is there a way to have everythning remain in alphabetical order?  The way it works now makes it difficult to find a specific folder or doc from a long list.

    In the Finder click the list icon and then sort by name. Is this what you mean?

  • Link between Purchase order and Attachment list

    Hi All,
    I got a requirement like Purchase orders are from moved from one system to another system.There was a bug in BDC program
    so some Attachment list of the purchase orders are not moved properly to the another system.
                                                   Now my client want a report to generate the Purchase orders which is having attachment list.
    I did not find any table link between Purcahase order and Attachment list.
                                                  So Plz provide me the link between purchase order and attachment list.
    Thanks,
    Ram

    You mean service for object services?
    if yes then u have to create one custom report for Generic Object Services   ( like notes , attachment  , url )

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

Maybe you are looking for