Need Help'bout Sort with Comparator!!

First of all, the object that Im using is named as "Node". This object has String name, int Value and some kinda things.
In the code below, I made one demantion object array ( Node[]) and filled it with unordered objects. And now I want to sort it by "int Value". There is a function "getVal()" which returns int Value.
Node[] arrlist = new Node[size];
Collect(current, arrlist); <-- this one collects unordered objects
java.util.Collections.sort(arrlist, new Comp());
and the class Comp is below
import java.util.*;
class Comp implements Comparator {
     public int compare(Object o, Object p){
          int answer = 0;
          if (o == p) {
               return 0;
          int node1 = ((Node)o).getVal();
          int node2 = ((Node)p).getVal();
          return node1 - node2;
I dont know much about the comparator. I dont even know what to return in thecomparator class. please help me guys!

You are on the right track. In the compartor, you have to return a negative value, 0 or a possitive value depending on the two values you compare..
some thing like this
public int compare(Object o, Object p){
//.... your codes here
int node1 = ((Node)o).getVal();
int node2 = ((Node)p).getVal();
if( node1 < node2 )
return -1
else
if( node1 > node2 )
  return 1;
else
return 0;
[url http://www.feedfeeds.com/feedtv]FeedTV

Similar Messages

  • Needed help in sorting values in StringBuffer

    Hi,
    I will get a StringBuffer as an input which contains lines in different order,
    Please refer the below example
    "A,B,C,D, LINE_NO=1"
    "E,F,G,H, LINE_NO=8"
    "I,J,K,L, LINE_NO=6"
    "M,N,O,P, LINE_NO=3"
    All the above four lines will be in the StringBuffer based on the above order,
    I need to create a new StrinBuffer order by Line_No.
    Can anyone help me on this..?

    Steps
    1) Split the StringBuffer content into an array containing the lines. You can use String.split() to do this.
    2) Create a java.util.Comparator that takes two lines and returns -1 if the first should be earlier than the second, zero if the two lines are considered equal and +1 if the second should be earlier than the first.
    3) Sort the array using java.util.Arrays.sort(array, comparator);
    4) Build a new StringBuffer from the sorted array.

  • Need help in sorting a column in classic report

    Hi I am trying to create and classic report and I need to do sorting on the columns. Also I am using a select list to filter the records in the column. When I am not using the select list the sorting is working but when I am using the selcet list and select the sort option then it is showing error. Can anyone help...
    Thnaks,
    Rik

    Select lists prior to v4 will sort on the return value. In v4, it sorts on the display value (as you're probably expecting). There's nothing really for you to fix here except if it's really important, see if you can get upgraded to v4.

  • Need help to start with some file and text manipulation

    Hello script mavens,
    I need help with starting a script that does the following:
    -within a base folder it takes an inventory (list?) of all the files (which happen to be image files).
    -creates a new folder inside the base folder and calls it imagesX where X increases by one every time the script is run
    -moves all the files into the images folder
    -within the base folder it creates a new text file and calls it imagesX.js
    -writes a "//-" into imagesX.js
    -then writes the list of filenames into the imagesX.js twice, separated by an empty line, and adds a semicolon to the end of each filename and saves imagesX.js
    -from a folder a level above the base folder it copies a file called index.html into the base folder and renames in indexX.html
    -in indexX.html it replaces a string "replaceThis" with "imagesX.js"
    The task is more complex but this would help me tremendously do the rest.
    If I am asking for too much on this forum please let me know

    This should get you started.
    The description of how you want to write the data isn't clear, but the rest should work (untested):
    property imageNum : 0 -- last used ImageNumber
    -- within a base folder it takes an inventory (list?) of all the files (which happen to be image files).
    -- get the folder:
    set baseFolder to (choose folder)
    -- now get the files within it:
    tell application "Finder"
    set fileList to every file of folder baseFolder as alias list
    end tell
    --creates a new folder inside the base folder and calls it imagesX where X increases by one every time the script is run
    tell application "Finder"
    set imageNum to imageNum + 1
    set newImageFolder to make new folder at baseFolder with properties {name:"images" & imageNum}
    -- moves all the files into the images folder
    move every file of folder baseFolder to newImageFolder
    --within the base folder it creates a new text file and calls it imagesX.js
    set textFile to (open for access file (baseFolder as text) & "images" & imageNum & ".js" with write permission)
    --writes a "//-" into imagesX.js
    write "//-" to textFile
    -- then writes the list of filenames into the imagesX.js twice, separated by an empty line, and adds a semicolon to the end of each filename and saves imagesX.js
    -- need more info here
    -- a blank line between each instance of the file name? or all file names, blank line, all file names again?
    -- an example, please
    close access textFile
    --from a folder a level above the base folder it copies a file called index.html into the base folder
    --and renames in indexX.html
    --in indexX.html it replaces a string "replaceThis" with "imagesX.js"
    -- the easiest way of doing this is to read the file and write a new copy with the changes - that's easier than changing it in situ:
    set indexHTML to (read file "index.html" of folder (container of baseFolder))
    set {oldTIDs, my text item delimiters} to {my text item delimiters, "replaceThis"}
    set indexHTML to text items of indexHTML
    set my text item delimiters to "imagesX.js"
    set indexHTML to indexHTML as text
    set my text item delimiters to oldTIDs
    set indexFile to (open for access file ("index" & imageNum & ".html") with write permission)
    write indexHTML to indexFile
    close access indexFile
    end tell

  • NEED HELP IN MATRIX WITH GROUP REPORT

    Dear All,
    I need small help in MATRIX WITH GROUP REPORT In Report Builder Test Report
    In my report, having periods as rows and location as columns as shown below,
    1) LOC-A
    JAN-10 FEB-10
    ITEM-GROUP -1 1 2
    ITEM-GROUP-2 3 4
    ITEM-GROUP 3 5 6
    2) LOC- B
    MAR-10 APR-10
    ITEM-GROUP -1 7 8
    ITEM-GROUP-2 9 10
    ITEM-GROUP-3 11 12
    But comming to my requirement, the periods should be in fix in matrix as shown below
    1) JAN-10 FEB-10 MAR-10 APR-10
    LOC-A
    ITEM-GROUP -1 1 2
    ITEM-GROUP-2 3 4
    ITEM-GROUP 3 5 6
    LOC- B
    ITEM-GROUP -1 0 0 7 8
    ITEM-GROUP-2 0 0 9 10
    ITEM-GROUP-3 0 0 11 12
    I am unable to get this kind of output format
    Please kindly waiting for reply from our team....
    Regards
    krishna.P

    For the periods, create a seperate dummy query and then use it as column group in the multi query matrix.

  • Need help  Pagination Suppourt with DataGrid

    Hi ,
    When i do a search Operation , the data from Database is huge and i think if i display all of them at a Time it will be a performance and response Time issue .
    So the question i am asking is that , can any body please give me a basic idea as how to implement Pagination with DataGrid Results ??
    Need help with Datgrid and Pagination suppourt .
    Thnaks in advnace .

    Hi Kiran,
    Try referring to the below link...
    http://www.flexicious.com/
    Thanks,
    Bhasker Chari.S

  • Replaced hard drive in compaq presario cq62, need help recovering it with out disks

    Recently replaced the hard drive in my notebook due to failure of original.  Need help recovering it without disks

    If you are wanting to install the original copy of Windows it came with, you will need a set of recovery disks.
    Otherwise, you can purchase a copy of Windows to install and download the appropriate drivers from http://goo.gl/hOm3. Just make sure the copy of Windows that is installed is at least the same family of Windows to ensure that drivers are available.
    What is the exact model of the notebook and product number?
    NOTE: Do not provide the serial number.
    ↙-----------How do I give Kudos?| How do I mark a post as Solved? ----------------↓

  • Need help from somebody with the "MSI KT6 Delta-FIS2R" motherboard

    Hi everybody!
    I really need some help from somebody with the MSI KT6 Delta-FIS2R motherboard (the one with onboard LAN, Audio, RAID, S-ATA and IEEE1394 firewire). You see. I've got this board myself but it's been destroyd. Some values for the onboard devices in my board has been overwritten so that windows no longer recognizes the onboard LAN and Audio controller anymore. I really need some help from somebody with this board.
    I need to see what the values for the onboard devices should be. I hope someone can help me by sending me a repport from the Everest home edition: http://www.lavalys.com/products/overview.php?pid=1&lang=en
    If anyone could do me this favour, I would be VERRY thankfull

    Quote from: HYSTERIAH on 12-November-05, 06:24:20
    I really need some help from somebody with the MSI KT6 Delta-FIS2R motherboard
    HYSTERIAH,
    With 76 Replies and 277 Views on your original thread, it looks to me like people have been trying to help you.
    So there is no confusion, I am locking this thread so all your help and advice you receive will be in the same place, so people do not need to jump between threads to keep track of what has already been suggested for this mobo of yours.
    Richard

  • Need help in sorting a alphanumeric DB column in BO report.

    Hi All,
    We have a DB column (Data type = varchar2).. with values..
    1                               
    1
    1.1
    1.1.1
    1.1.1.1
    1.2
    1.2.1
    1.3
    1.3.1
    1.3.1.1.1
    Desired
    1
    1.1
    1.1.1
    1.1.1.1
    1.2
    1.2.1
    1.3
    1.3.1
    1.3.1.1.1
    2
    etc..
    We need to sort this column in BO report.. any idea..  we have sorted it in the Query which is giving right output in pl/sql developer but in BO sorting is not showing properly.
    Could you help please to achieve this?
    Thanks and Regards,
    Priyashree

    The Record Sort Expert appears when you choose the Record Sort Expert command from the Report menu.
    Use the Record Sort Expert to define how you want the records in your report to be sorted for printing. You can add and remove a sort field and define the sort direction (ascending or descending) for the data in your report.
    In my version Record Sort appears as a   A over a Z with Arrows pointing from A to Z, and Z to A.  It is next to group expert, which looks like a mountain with an arrow pointing up.  Both are on the "Expert" tool bar.

  • Love the X2 except for 3 main issues which I need help or clarification with

    Hi Everyone, I have pretty much copied and pasted my post from the Motorola forums (with a few minor edits) over here as I do need a little bit of help or insight on my issue.
    I have scoured through the Droid X section trying to find solutions to my problems and I haven't been able to get a solid answer anywhere (here or on other Android/X2 forums).
    I have an X2. I really like this phone. It is solid and has crystal clear sound quality. However, ever since I have had it I have seen intermittent issues pop up and I would like to get some feedback on them or get things put into perspective that it is a known glitch in the interface between the Android OS and the hardware. I bought the phone at Best Buy and every time I bring it in (either back to Best Buy or a Verizon store), as the issue is intermittent, they won't replace the phone. The people at Best Buy have told me to "do a battery pull every morning" which completely offends me as I never had to do anything so drastic with my original Droid until it finally decided to reboot on me every 2 hours (this is when I upgraded to the X2). I had to pick it up from Best Buy as I needed a functional phone immediately and no Verizon store in the area had the X2 in stock.
    The first (and most important issue)... Every once in a while, even though I have full signal, when somebody calls me, my phone will not ring or vibrate. It will ring the full six times on their end but does not show up on my phone as ever receiving or missing the call. After the six rings on their end, it goes to voicemail and after they leave the message, only the voicemail indicator shows up. Over the past month this has happened multiple times (once or twice a week). Those who don't leave messages have had to hunt me down because they thought I had left my phone elsewhere as it never rang or notified me of an incoming call.
    The next two issues are still important to me but they are more of an inconvenience than anything else.
    Sometimes (yes, this is intermittent too but it happens daily), when I wake my phone from sleep, all of the antennas seem to be off and it takes a good second or two to show back up in the status bar (3G, Bluetooth, etc). My question is, have all of the non-CDMA antennas "gone to sleep"? The signal bar for the actual cell service are still there, just not the other services (3G/1X) or wireless settings (Bluetooth/WiFi) for a couple seconds.
    Lastly (and this may be a direct link to the previous question), when I use the "Google Talk" application, the messages I send go through very quickly, but sometimes I do not get replies for a long time after they are sent (30 minutes to and hour later). If I wake the phone, sometimes a previously sent message will come through, and when I check the chat log in Gmail itself, the message was sent from quite a while back (15 minutes to an hour).
    I know I am brand new to your community, and I am sorry to have to burden you all with a post like this as my initial post. However, I have always liked and used Motorola phones with Verizon/GTE (all the way back to the MicroTAC series of the early 90s) without issues or incidents for the most part. As my original Droid was starting to act up I decided to jump on the X2 as it was just released. I understood that it was not going to initially come with Gingerbread and I said I would be patient for the update to come and hopefully it would bring a new level to the phone itself as well as solve some (if not all) of the issues. However, now that it is past my return date, and there is no update as of yet, I do require assistance.
    Thanks in advance for any assistance or insight,
    Tuan

    Thanks for the replies everyone.
    The responses I received over at the Moto forums said the same thing about the battery saver mode. However, I have had the same issue with the radios shutting off during the day while it is in "Nighttime savings mode" so I'm just thinking it's an oddball glitch with the phone's power management settings and clock. I have recently changed the battery mode to "Performance Mode" from Nighttime Savings" as I have the phone plugged into the charger at night anyways. I'm hoping that will take care of both my radio and gtalk issues.
    @Wildman: I have heard the same thing about the GB update from a Verizon rep very recently myself. I am still going to hope for an update sometime in the near future, but I do recall the first update for my Original Droid was months down the line from the release day.
    @Droiddude: Are you just cycling the power? Or are you actually doing physical battery pulls? If cycling the power works for you it would lessen the burden of pulling that Incipio case (Verizon Double Cover) off my phone every time to do battery pulls. It's a great case but wow it's a tight/snug fit.
    @vereyezuhn: I understand that there are possible dead areas in which my main issue may occur. I even have a prepaid phone for the times I am in a Verizon dead zone. However, when my issue occurs, I will be in the same spot for a while. I will receive all my calls, miss one in the manner I have spoken, then receive the following calls normally (SMS/MMS does not seem to be affected either as I seem to receive all of those). This is why I have this specific issue. I have recently cleared the phone's cache partition as well as update the PRL using *228 option 2. We will see over time if this eliminates the issue or at least makes it much more rare.

  • Need help big time with pop-up window!

    This is probably an easy answer, I'm not a programmer or a back end guy whatsoever, I'm a graphic designer trying to make his way through a project for a client.
    I'm working up a Flash template, and I need to make a simple pop up window that will view a more detailed version of an image.  The template has a pop up window system where you add your photo to a certain frame of a movie clip.  The problem is, the pop ups have scroll bars built in, and for the life of me I couldn't figure out how to get rid of them, so I duplicated one of the movie clips that looked like it housed the framework of the pop up and deleted the scroll bar (I didn't delete any of the scroll bar code because I had no idea what I was doing).  It actually kind of worked, but the pop up window is a bit too wide and doesn't look right.
    You can view my hack job here...
    http://truetilldeathhq.com/main8_v7/main8_v7.html
    Stay on the "Print" page and click the first "01" button and an ad for Ford will come up.  Click the "Detailed View" button in the description to see the pop up window.
    My question is, there MUST be an easier way to make a pop up window than the workaround I'm using with the template.  What I'm trying to do is have a pop up for each sample of the work (all images would be the same size) for the first four buttons, and then for the "Online Banners" page, have the pop up open up to the dimensions of the particular banner ad and play the swf.  The pop ups shouldn't have scroll bars, only a title and the button to close the window.
    To view the template files, you can download them at:
    http://truetilldeathhq.com/main8_v7/main8_v7.fla
    The "descripton" movie clips have the descriptions and the "Detailed View" links in the frames, and the movie clips I not so gracefully butchered to get the pop up to work were TM_page_content_scroll (where you're supposed to put an image in a certain frame and then put the # of that frame in the Actionscript of the "Detailed View" button), and the TM_main_cont_page2 and TM_pop_up_main3, which were the ones I duplicated.
    If ANYONE can offer even the slightest bit of help, I gratefully appreciate it.  I've been working on this thing for like 15 hours a day and I can't even think straight at this point, thanks!

    I admit to not having read everything you wrote... there's just too much of it. But...
    Hashtable (and HashMap, which you should really be using unless you have some external constraint requiring the use of Hashtable) map each key to a single value object.
    That is, you can map from the key string "4996" to one single other object. And then you can also map from a different key to a different object.
    In you put() method, you add a mapping from "4996" to "good", and then you replace that mapping with one from "4996" to "home". There is only ever one value associated with a given key.
    To map multiple values to a single key, you need the value object to be a collection of some kind (or an array). So, you could map your string "4996" to a List, and that list could contain the strings "good", "home", etc.

  • Need help displaying images with List component for Flash CS4 (ActionScript 3.0)

    Hi folks:
    I am an inexperienced user of Flash CS4 Pro (v10.0.2). I am attempting to use the List component with ActionScript 3.0 to make a different image display when a user clicks each item in a list.
    I did find a tutorial that showed me how to make different text display using a dynamic text box and the following ActionScript:
    MyList.addEventListener(Event.CHANGE, ShowSelectedItem);
    function ShowSelectedItem(event:Event):void {
        ListText.text=MyList.selectedItem.data;
    ...where My List is the instance of the List component and ListText is the dynamix text box. In this case, the user clicks an item in the list, defined by the label value in the dataProvider parameter of the List component, and text displays as defined in the data value in the dataProvider parameter.
    However, as I mentioned to start, what I really want to do is make images display instead of text. Can anyone provide me the steps to do this?
    I appreciate your help (in advance)!!
    Cindy

    Hi...thanks for responding! I was planning on using images from the Library, but if there is a better way to do it, I'm open. So far, I just have text in the data property. This is part of my problem. I don't know what I need to put in the data value for an image to display. Do I just put the image file name and Flash will know to pull it from the Library? Do I need to place the images on the stage on different frames? I apologize for the "stupid user" questions, but as you can tell, I'm a newbie.
    Appreciate your patience and any help you can offer!
    Cindy

  • Hi i need help in  sort in out issue in worflow in sap EDI

    i sap gurus
    i have two issues in sap workflow .can u guys help me out in sorting out these issues.
    1) When checking out/reserving a work flow item(TC: SBWP), there is no option to display who has it checked out. When the workflow item is reserved, it is removed from everyone elses workflow list. It can happen that people put these back at the end of the day, when there is no time to work on them any longer. <b>It would be a great help to have visability to all items even if they are reserved, and to have a name associated with it to see who has it reserved.</b>
    2) In the "Change Layout" option of work flow (TC:SBWP), there are dynamic fields that look like they could be assigned. Perhaps one of these could be used for the person doing the reserving, but in addition to this, i<b>t would be very helpful if customer number could also be populated in one of these fields. This would allow sales specialist to pick up work flow items by customer.</b>
    thanks in advance
    sam sd

    Hi Sam,
    As far your first requirement concerned,I don't think it is possible.
    because reserveing of workitem is to prevent other users from executing it.
    So you can't just have the workitems only for display in other users inbox even after someone else reserved it.It defeats the own purpose.
    I would suggest you to go for a report kinda tool where you can actually help the users have the visibility.
    About second one,you use tcode SWL1 to define the dynamic columns and enter the container elemet ther to have the customer number displayed.

  • I need help making tables with all my data. What to do with all my Data?

    Hello All,
    Here is the scenario. I have about 10 columns of data. It has Name of Item. Price sold, Shipping Cost, Address and others.
    I want to group all the same items into a separate table with its own totals. There is 100 different items, So i need to split is several tables. Any idea on how to do this? Can It be done in Numbers?

    A variation to Jerry's suggestion:
    You are inquiring about creating 100 tables that produce summaries, 1 for each item. Jerry suggests a single table showing only a summary of your 100 items. This has potential. If you want to see the individual lines displayed above each summary, you may be able to use your original table. This process, however, involves a little work. But it's not unreasonable and may satisfy your needs.
    In your original table create a new line for each item. These lines are basically blank except for the item name and whatever columns you want to summarize. Enter the item names on these lines but follow them with the word " Total". When you sort on the Item column these lines will appear as the last of each item. Then place the SUMIF function in the proper column to obtain your summary.
    pw

  • Need help integrating flash with asp

    i am creating a dynamic site that pulls all of its content
    from and access database. i would like to make the entire page in
    flash. i have never used flash to pull any content from a datbase
    before. does any one know how to do this ? or know of a good
    tutorial? i can only seem to find tutorials for flash 8 or flash 5,
    nothing for mx2004.
    it seems like every thing i try doesnt work and no one knows
    how to help me.
    feeling very discouraged,
    -furley

    Flash has nothing to do with getting data from an Access
    database.
    You need to focus on either ASP or ASP.Net, a scripting
    language for the
    server script either JScript or VBScript, middleware usually
    ADO or ADO.Net
    and finally SQL. All of these items go together in a server
    side script that
    could work with non-Flash or Flash client interfaces. You
    should find many
    tutorials on the internet with these items as it has been
    done for nearly a
    decade.
    You also can use ColdFusion.
    For Flash, you need to learn LoadVars Actionscript class if
    you plan to
    communicate data in the URL Variables format or XML
    Actionscript class if
    you want to use XML data format. It will not really matter to
    Flash what is
    on the server side as it will only be sending and receiving
    data in either
    of those two data formats (URL Variables or XML).
    If you want to look at some Using VBScript, ASP, ADO and an
    OLEDB Connection
    examples I use for seminars in Web database you can take a
    look here:
    http://www.hosfordusa.com/ClickSystems/courses/webdb/.
    However they lack
    Flash example but would work "as is" with a Flash example.
    Once you look at some of those options, you can then form
    more specific
    questions for this forum and especially with using the
    LoadVars and XML
    Actionscript classes or the XML connector Flash component.
    Lon Hosford
    www.lonhosford.com
    Flash, Actionscript and Flash Media Server examples:
    http://flashexamples.hosfordusa.com
    May many happy bits flow your way!
    "professorfurley" <[email protected]> wrote
    in message
    news:[email protected]...
    i am creating a dynamic site that pulls all of its content
    from and access
    database. i would like to make the entire page in flash. i
    have never used
    flash to pull any content from a datbase before. does any one
    know how to do
    this ? or know of a good tutorial? i can only seem to find
    tutorials for
    flash
    8 or flash 5, nothing for mx2004.
    it seems like every thing i try doesnt work and no one knows
    how to help
    me.
    feeling very discouraged,
    -furley

Maybe you are looking for

  • General Java3D Art question

    Hello everyone, was hoping that someone could point me in the direction of any documentation that might exist for guidelines on building 3d models and graphics for Java3D. Ideally, it would include information about what features are supported, and h

  • ConnectionFactory createConnection()??

    Hi, I found the following on the J2EE tutorial on [http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html], Chapter 33. * Look up connection factory and destination. If either * does not exist, exit. If you look up a * TopicConnectionFactory or a

  • How to induce a delay of 1 min between to activities in OSB

    We have requirement to induce delay of 1 min in between 2 OSB activities, can you please let me know how to do that? Is there any function like sleep/delay available?

  • Question On 16x9 Aspect Ratio

    I set Easy Setup to DV-NTSC Anamorphic and captured my 10 hours of underwater video from Mini-DV that was shot in 16x9 (not HD). I then created my video, including stills, title text etc. When I watch my project, my titles and still pictures take up

  • Best practise Analyzer for File Server

    Hi Team, I have a file which are running in windows 2003 server, we are going to migrate this server to another server which will be in 2008. I need best practice Analyzer or any tool, so that we can check file servers performance and data ,DFS Data.