Sorting values added to an array

Hi,
I've written some code to sort value in an array as I add them, but I can't get it to work properly. So far I have:
public boolean add(int next)
        int last, temp, previous;
        if (size < 1) // checks whether any values have been added to determine correct value for previous.
            previous = size;
        else
            previous = size - 1;
        if (size < arraySize) //determines whether array is full or not
            last = numberList[previous];
            if (next > last)
                numberList[size] = next;
                size++;
            else if (next < last)
                temp = last;
                numberList[previous] = next;
                numberList[size] = temp;
                size++;
            numberAdded = true;
            return numberAdded;
        }Which does add the numbers, but they aren't arranged into the proper order. When I look over it I can't see anything that stands out as being wrong, so I was wondering whether anybody could see anything?
Thanks for your help,

endasil wrote:
nickd_101 wrote:
I don't want a loop in this case, as i want to put the values into the correct position (with respect to the previous one) as they're added into the array. Basically, my idea is that the previous value is checked against the new value and then they are swapped if the previous value is larger than the new or kept as is if not.So you're saying that if you added
1, 2, 4, 5, 3
you'd want the resultant order to be
1, 2, 4, 3, 5?
Because by your logic that's what would happen. The most that can ever happen by your logic is that a new entry would be at most 1 away from the end of the array.
P.S. use an SortedSet, given that your code doesn't allow duplicate values anyway.
Edited by: endasil on Nov 19, 2007 2:15 PMThanks for the response. What I meant is that I would eventually want it in ascending order 1,2,3,4,5. What I thought I was doing was sorting the comparing the new value with the preceding everytime a number was added so that it would always go in consecutive order. So, for example say the numbers were added to the array one by one in the order 3,5,4,1,2; 3 would be compared to 5 and there would be no change in the position. As i've typed this out i've just realised the massive logical error i've made! Could you point me in the right direction to get this to work as i'm new to this. I've managed to get a pre-defined array sorting as normal, but for this i need to sort everytime I add a new value?
Thanks again

Similar Messages

  • Sort values of structure with arrays

    Hi
    For a shopping cart I'm using a structure with arrays to store the items in the cart. I tried to use StructSort but did not work...
    This is how I store the items in the cart:
    <cfscript>
                if (not(isdefined("session.cart"))) {                // Check to make sure that the Shopping cart structure exists.
                    session.cart = structnew();
                // The item structure we are going to use to store the items in the cart
                // is going to have four parts...
                //         1.  The item id
                //         2.  The item name
                //         3.  The price per unit
                //         4.  The quantity
                tempvalue = listtoarray('#attributes.id#,#attributes.name#,#attributes.price#,#attributes.quantity#') ;
                // if the item is not yet in the cart, simply add it to the cart
                if (not(structKeyExists(session.cart, attributes.name))) {
                    StructInsert(session.cart,attributes.name,tempvalue);
                // if the item is already in the cart, update the item quantity
                else {
                    tempvalue[4]=session.cart[attributes.name][4]+attributes.quantity;
                    StructUpdate(session.cart,attributes.name,tempvalue);
    </cfscript>
    Any help will be appreciated.
    Thank you.
    TJ

    To loop over an array one has two options:
    <cfloop index="i" from="1" to="#arrayLen(a)#">
    Or:
    <cfloop index="someVar" array="#a#">
    Personally I use the former because I think the implementation of array-looping with <cfloop> is cocked-up as it's not the index that gets put into "someVar", it's the array element itself.  So by way of pedantic protest, I don't use that syntax.
    But anyway...
    The reason why your struct is unordered is because structs are - innately, and by definition - unordered.  If you want an ordered data structure, you use an array.
    However what you are wanting to do is to sort your array by a subkey value of the structs the array contains.  If you want to do that, you will need to roll your own sorting solution.
    Personally I'd stick with using an array and just use its intrinsic ordering (the order in which items are added to it).  However if you wanted to sort on one of the inner struct keys, you could maintain a separate struct keyed on the value you wish to sort on, containing a reference to the array element in the original array.  Then you could extract a structKeyArray() from that, and use arraySort() to order those index keys in whichever order you like.
    Adam

  • Value-added tax problem about free goods!

    Hi All,
    I've got a value-added tax problem.....
    Can anyone can come out with a solution.
    Here is the Business Scenario....
    One product company offen give some free goods to its customer company for test or probation. In pricing, the free goods have no income so that the value-added tax is zero, but by the law, the product company must pay the VAT(value-added tax) base on the cost of the free goods.
    How to implement this in SD R/3 Scenario...
    Can any one of you suggest me a solution for this plz..
    Regards,
    wang-yuzhen.

    Hi,
    You need to bring in a consition type "VPRS" in your pricing procedure. The VAT will be determined based on this condition type. VPRS is a statistical condition type. That means eventhough it appears with a value it will potentially not be displayed in your invoice. The invoice value will be 0 and there will be no account posting for this condition type

  • Tecra A8 PTA83E - Value Added Package installation

    Tosiba Tecra A8 PTA83E
    Microsoft Windows Vista Ultimate X64
    I've been unable to install the Toshiba Value Added Pack (vap-vista-1011btn-en) or any version before it. I have spoke to Tosh tech support on numerous occasions and they always promise Customer Support will respond to the query, they never do.
    Toward the end of the installation, whilst it is running the "Computing space requirements" process an error dialogue box pops containing "ID_ERR_NOTINSTALLVALZ_MESSAGE". The only option available is "ok" and when this is selected the install rolls back and the finish screen says "The wizard was interrupted before TOSHIBA Value Added Package could be completely installed".
    I am, as I am sure you can understand, VERY frustrated with this problem. I purchased (the very expensive) Vista Ultimate as Toshiba claim this Laptop is Vista ready, and it may well be, but the drivers and software provided are not. I am also having problems with:
    Bluetooth
    Config Free Utility
    WinBIOS updater
    Sound Driver
    Graphics Driver
    I will save these problems for another thread as I would like to deal with these problems one at a time.
    Thanks in advance for any help given/offered.

    Hi
    You are running the 64bit version of Vista???
    Im not very surprised that you are not able to install the Toshiba Vista Value Added Package.
    All the drivers, tools and utilities are designed for Vista 32bit version!!
    In my knowledge the 32bit drivers dont run on the 64bit Vista OS!
    Regarding the ID ERR NOTINSTALLVALZ MESSAGE error message;
    It seems the BIOS update could solve this issue.
    This was reported in different threads here in the Toshiba forum!!!
    For example:
    http://forums.computers.toshiba-europe.com/forums/thread.jspa?threadID=20471&messageID=75256
    or
    http://forums.computers.toshiba-europe.com/forums/thread.jspa?threadID=21232&messageID=78197
    greetings

  • How to display the sort value in the selection screen in the report title

    Dear All,
    How to display the sort value in the selection screen in the report title? I have selected a value in the selection screen for sorting , but i need that values by which i have sorted with in the report title. Can you please throw some light on this!!
    Good day,
    Thanks and regards
    Arun S

    Hi Arun,
    Try this.
    1, Set one dynamic parameter,
    2, Drag and drop that parameter into  your report title.
    3, Pass the value(sort value) dynamically from your application,
    4, Cheers..
    Other wise Try with Dataset, create a dataset and fill thev alue into that.. Then  set the data source from CR designer. and darg and drop that data column into the report.
    Hope this will work,
    Regards,
    Salah
    Edited by: salahudheen muhammed on Mar 25, 2009 11:13 AM

  • How to set variable value in an XML array

    Hi,
    Please let me know how to set the value for a xml array element using assign activity inside a for-each block in BPEL 11g
    I tried to set the variable value for result element using the below condition but i encountered selection failure message
    $outputVariable.payload/ns1:Student['i']/ns1:result or
    $outputVariable.payload/ns1:Student[$i]/ns1:result
    And the xsd used is as below
    <xsd:complexType name="StudentCollection">
    <xsd:sequence>
    <xsd:element name="Student" type="Student" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="Student">
    <xsd:sequence>
    <xsd:element name="Name" type="xsd:string"/>
    <xsd:element name="location" type="xsd:string"/>
    <xsd:element name="mark" type="xsd:string"/>
    <xsd:element name="result" type="xsd:string"/>
    </xsd:sequence>
    </xsd:complexType>
    Thanks,
    Dhana

    Hi,
    At the back of button specify the following parameter:-
    CMD    1        Execute_planning_function
    Planning_function_name  1   xyz
    Var_name     1    variable_name
    var_value      1    blank
    Can also refer to link below:-
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b0a89464-f697-2910-2ba6-9877e3088954?quicklink=index&overridelayout=true(can refer to page 20)
    http://www.sdn.sap.com/ddc5564a-337d-4cf9-a34e-2dab64df09be/finaldownload/downloadid-a61a6724ba8e7b7fbd9c5df9590ab50d/ddc5564a-337d-4cf9-a34e-2dab64df09be/irj/scn/go/portal/prtroot/docs/library/uuid/f0881371-78a1-2910-f0b8-af3e184929be?quicklink=index&overridelayout=true
    Hope it may help

  • Reg creation of  value added service with delivery material

    hi
    I want to create the material which is used for the value added service with delivery .do u know the material type for creating the service material other than material type 'dien '. if i use the material type as ' DIEN ' , then i can't create the shipment. in  my scenario , i need to create the shipment. kindly help me in this scenario with the material type & the procedures

    hi
    I want to create the material which is used for the value added service with delivery .do u know the material type for creating the service material other than material type 'dien '. if i use the material type as ' DIEN ' , then i can't create the shipment. in  my scenario , i need to create the shipment. kindly help me in this scenario with the material type & the procedures

  • Value Added Services Printing

    Hi,
    Can anyone give me some instructions on how to print a VAS order?
    When I try to print a VAS order template, I just get the message "Some error occured during printing".
    Debugging it I found that some values are missing but I don't know where to define them (e.g. spool parameters, form, ...).
    During VAS order execution, the transaction aborts after the error message is being sent.
    Additionally, I didn't get a VAS order when I set the execution mode in the template to "during TO execution". When I confirmed the TO and wanted to post the goods issue for the shipment I got the error "Can't post goods issue, unconfirmed VAS orders exist". That I got the error is correct, since I set this up in customizing. The problem is that I can't find the VAS order despite confirming it. Any idea?
    The ideal process would be as follows:
    1. Create a shipment and VAS order for specific materials.
    2. Create the TO for the shipment and start and print the VAS order.
    3. Confirm the TO.
    4. Confirm the VAS order.
    5. Post goods issue.
    As a "workaround" I could live with the following process:
    1. Create a shipment and VAS order for specific materials.
    2. Create the TO for the shipment, start  the VAS order (ideally print some information on the VAS order).
      The TO is rerouted to a different storage type.
    3. Confirm TO.
    4. Process and confirm VAS order at work station.
    5. Create and confirm TO to goods issue area.
    6. Post goods issue.
    Can anyone help me with those processes, especially with the printing problem?
    Thanks in advance.

    Hello Raj ,
    VAS stands for Value-added Service. It is an operation performed on materials,
    which enhances their value, worth, functionality or usefulness.
    In a customer scenario, the customer might request some specific service to the
    goods before they are delivered.
    Some examples being
    1.     Company logo printed in a t-shirt
    2.     Special packing of the shirt
    3.     Labeling the material
    You can find more information in the link
    http://help.sap.com/saphelp_afs60/helpdata/en/index.htm
    Sales and Distribution -> Basic Functions and Master Data in the AFS Sales Processing -> Value-Added Services
    Regards
    Sudha

  • About pricing and value added tax

    Dear Friends,
    In the standard customer order screen (VA01), when I enter Price value, I want SAP to determine
    *Value Added Tax(standard%18) automatically.
    Can anyone tell how to accomplish this step by step?
    Sincerely,

    Hi,
    Yes, this is there in standard SAP.
    You can configure it in your pricing procedure so that when you enter the price (PR00) system will automatically calculate the VAT percentage for that and display.
    IMG path:
    SPRO - > Sales and Distribution / Basic Functions / Pricing / Pricing Control / Define And Assign Pricing Procedures / Maintain pricing procedures
    Go in to that node.
    Then select the relevant pricing procedure (Check: RVAA01 as a example)
    Double click on "Control Data" node
    You can see PR00 appear as the price condition
    If you go down in the procedure you should be able to see condition MWST appear in the procedure.
    MWST is same as VAT (Tax condition)
    If you want to use different condition other than MWST, copy MWST and do that.
    Then you need to maintain VAT % in VK11 as well. In this case, go to VK11 enter MWST and maintain 18% there for relevant customer and material tax combination.
    Then try with a new sales order. You should be able to see the Tax calculation once you enter price.
    Best regards,
    Anupa

  • How to find the nearlest value in 1-D array ?

    Hi.. everybody..
    I need to seperate the raw data(1-D) into 2 group of array by the center value and then make the average value in each array. But I also still have the problem about if the center value is not the same of some value in the 1-D array. I cannot use the split function.
    "How to find the nearlest value to the center point that I calculated, in the 1-D array ?"
    Thanks a lot for anybody help

    In a general sense, since I'm not sure what your data values are or how far away your calculated center is from the true value, I would do it one of two ways:
    1) Use a threshold value and scan the array until the threshold is reached (assumes constantly increasing values in the array).
    2) Use either a) round to nearest integer b) round to + Infinity (round up) or c) round to - infinity (round down). If you don't have decimal values, you'll have to devide the values by a power of 10.
    2006 Ultimate LabVIEW G-eek.

  • What is Value added project stock and how can we track it.

    Hi all,
    There is one query in PS.
    Please guide me about Value added project stock and how can we track it.
    any information regarding this will be highly appreciated
    Thanks & Regards
    Shiv

    Thanks Thorsten for reply.
    Can you please provide the liink or any document you have.It wil be usefull to me
    shiv

  • MS Outlook on O365 versus FingerPrin​t software or Value Added Package

    Hello all, I have problem - after installing FingerPrint software or Value Added Package some functionality in MS Outlook 2010 on MS O365 system stops working  like planning share meetings. I mean so problem in the Security - this application close some ports or something...
    You have a solution or idea? 
    Alex

    Removing old and installing new VAP is definitely not risky. I have done this many times without any problems.
    The latest version is much better and the flash cards are shown much faster than with old version. I can really recommend you to remove preinstalled version and install the latest one.

  • Access values stored in 2D Array in HashMap

    Hi everyone i would like to know how to access values stored in a 2D array inside a HashMap
    Here is a drawing representation of the map.
    So to get the KEYS I just have to execute this code:
    this.allPeople = personInterests.keySet();But how can I get acces to the actual values inside the 2D Array?
    My goal is to create a treeSet and store all the elements of the first array in it, then look at the second array if any new elements are detected add them to the treeset, then third array and so on.
    I tried this code:
    Object[] bands = personInterests.values().toArray();
         for( int i=0; i<bands.length; i++)
              this.allBands.add(bands.toString());
    }But this.allBands.add(bands[i].toString())seems to be the problem, Dealing with a 2D array, this code only return a string representation of the Arrays and not a string representation of their elements.
    Using my logic I tried to execute:
       this.allBands.add(bands[0][i].toString());But i get a ARRAY REQUIRED BUT JAVA.LANG.OBJECT FOUND
    I really don't know the way to go.
    Thanks to anyone that will help.
    Regards, Damien.
    Edited by: Fir3blast on Mar 3, 2010 5:27 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    You'll just need to cast the object to the correct type. This is nothing to do with HashMap at all. If you don't know what that means then your google keywords are "java cast tutorial".

  • Blank value added to dropdown list in Adobe Interactive forms

    Hi,
    I see blank value being added to the value list by default to dropdown lists in adobe interactive forms. The real issue is it's being added sometimes as the first value or last value in the drop down list of values which is inconsistent and resulting in Errors sometimes.
    Is there a way by which we can control the position of the blank value added by default(SAP or Adobe) to the drop down lists in adobe interactive forms .? Secondly , Is this a SAP or Adobe upgrade issue since we observed this issue only after recent upgrades ...?
    I am using HCM processes and forms and I am not adding blank value (space) explicitly in my coding of dropdown list values .
    Thanks for your time .
    Sankeerth
    Edited by: SANKEERTH D on Aug 22, 2011 1:46 PM

    Hi Sankeerth,
    The Web Dynpro framework generates a blank entry to the value set of the dropdown listbox if the Context attribute bound to the dropdown listbox is "nullable" (see properties of the Context attribute).
    The dropdown listboxes of interactive forms will be populated with exactly the same data (value sets) as the "native" Web Dynpro dropdown lisboxes.
    For SAP NetWeaver 7 EhP2, there's a Web Dynpro test application (WDR_TEST_ADOBE_ZCI) available, which demonstrates this: Start it and see the dropdown listboxes labeled "Datatype" and "Datatype (nullable)": Both are bound to Context attributes which are of type DATATYPE_D. The only difference is that one of the attributes is "nullable". The dropdown listbox bound to the nullable attribute contains the additional blank entry.
    Watch the native Web Dynpro dropdown listboxes below the interactive form: They are bound to the same Context attributes and contain the same value sets as the dropdown listboxes of the interactive form!
    Regards,
    Ralf

  • XI Message Protocol and Value-Added Web Services

    Hi,
    I have a couple of questions on the above-mentioned topic:
    - How is the enhanced SOAP format in XI able to deliver value-added web services (as described in the XI documentation)?
    - If the XI format is an enhancement of SOAP, is it again fully open or are there some proprietary pieces to it?
    Thanks and Regards,
    Bharath

    Hi Bharath,
    >>> How is the enhanced SOAP format in XI able to deliver value-added web services (as described in the XI documentation)?
    value-added web services means that you can monitor
    all web services from one place (with the xi monitoring features)
    if you're using point-to-point connections without the XI
    you have to monitor all of your flows from all those applications and not from just one place
    Regards,
    michal
    <a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions">XI FAQ - Frequently Asked Questions</a>

Maybe you are looking for

  • How can I get the icloud download to run/install on my pc?

    I have downloaded the app several times, run it, but it does not show up in my programs list or on my desktop. When running the download, I get a "repair" or "uninstall" option, not an install. I choose the repair. Something is missing, but what? I a

  • PHDs on multiple computers, NHDs on others

    I'd like to set up a system in which each user has one (or perhaps more than one, if possible) computer on which they use a portable home directory, but I'd like to allow them to log in from other people's main machines using their network directory.

  • IPhone and iPad not being recognized by iTunes

    Hi All, I had a late 2007 macbook pro that developed a line across the screen where everything below it was gray. At first it was a simple 'wiggle of the screen' fix, then it evolved into a 'put a bag clip on the side', then it became a 'put a bag cl

  • Disk Utility buggy?

    When I start Disk Utility (on Leopard), I get the following worrying messages: <pre>EBMacPro:Contents eboily$ MacOS/Disk\ Utility 2007-11-03 09:52:33.655 Disk Utility[7896:10b] Error loading /Users/eboily/Library/Plug-ins/DiskImages/VirtualPCDiskImag

  • Append swf file - Spry.Utils.updateContent - not work

    I don't understand this When I try to add swf file to Spry Tabbed Panels content - everything is OK. Now - in tabbed panels content I want to insert data from external html files. In this external file I have swf file and text, and images. When I pre