CutinTwo function for lists

I'm trying to do this CutinTwo function to use in another function called generalsort.
This function takes in a list, and returns 2 lists that are the result of splitting the list that is takin in by the function. I got the base case, but I'm having trouble with the recursive call. My problem is, I'm trying to get a pointer to point to the middle element of the list, so that way I can cut the list in half.
Here is what I have so far:
public void CutInTwo(list L1)
          list L2 = new list();
          if(L1.size == 1)
       return;
       else
                  Node current = L1.head;
                  int temp = L1.size / 2;
                  /*this part is the problem.  I can't figure out how to get to the middle
                of the list.  The temp variable will return the the position where the   
               pointer should be, but lists and integers are not of the same type, so
             how can I find out the middle of a list by using only list variables.   */
        }Thanks

Lol,
yea, it's for an assignment for school. Believe me if I wouldn't have had to write my own list class, I wouldn't have.
This is the actual question I'm working on, if anyone cares to see:
2. QUESTION 1b
Write a function GeneralSort that meets this specification:
     Inputs: a list L, and a procedure CutInTwo that meets the specification below
     Outputs: L' (i.e. L is changed), and two integers: Nc, Njs
     Preconditions: L is defined
     Postconditions: L' is sorted in increasing order. Nc is the total number of times
          two list elements were compared during the sorting process, including the
          comparisons made by the Merge and CutInTwo functions. Njs is the total
          number of join and split operations that were performed during the sorting
          process, including the joins and splits done by the Merge and CutInTwo
          functions.
     GeneralSort must use the "general sorting strategy" (described in detail in class):
     1. Use the procedure CutInTwo to divide L into two pieces
     2. Recursively sort the two pieces
     3. Merge the results (use the function written in Question 1a).
The function CutInTwo meets this specification:
     Input: a list L1
     Outputs: L1' (i.e. L1 is changed), L2 (a list), and two integers, Nc and Njs
     Preconditions: L1 has 2 or more elements
     Postconditions: neither L1' nor L2 is empty, and collectively they contain all the
          elements of L1 (and nothing else). Nc is the number of times two list
          elements were compared during the cut_in_two process. Njs is the total
          number of join and split operations that were performed during the
          CutInTwo process.
right now I'm having some trouble with the syntax for the generalsort recursive call and the merging of the two lists.
If anyone can help me out, that would be great,
Thanks

Similar Messages

  • SORT functionality for list of fields

    Hi all,
    I dont have a table control in which I have the custom fields.The custom fields are placed in a subscreen within acustom tab in standard screen in tcode VL31N. as shown below:
    Plant:
    Carrier:
    Bill of lading:
    Packaging list:
    Damage
    Now below these 5 fields ,I need to display the 2 SORT buttons/icons to change the display in ASCENDING OR DESCENDING order.
    How do i do this???Is there any std FM ?

    I Dont think its possible dynamically, but you can have 2 normal screens which will be called to subscreen based on the user action (button 1 - First screen & Button 2 - Second screen). you can try with MODIF ID too.

  • User Interfaces for Lists

    hi,
    How to create user interfaces for lists
    thanks.

    HI,
    The R/3 system automatically, generates a graphical user interface (GUI) for your lists that offers the basic functions for list processing, such as saving or printing the list. If you want to include additional functionality, such as pushbuttons, you must define your own interface status. To create a new status, the Development Workbench offers the Menu Painter. With the Menu Painter, you can create menus and application toolbars. And you can assign Function Keys to certain functions. At the beginning of the statement block of AT END-OF-SELECTION, active the status of the basic list using the statement: SET PF-STATUS ‘STATUS’.
    Cheers,
    Chandra Sekhar.

  • Query for listing several values in same field

    Hi,
    is there a function for listing more than one value in the same field, only with comma seperation?
    For example, I want to group by cardcode from ORDR and list all docnum's like this:
    Cardcode    Docnum's
    21355          98765, 95498, 95164
    21564          95484, 54684, 95654, 98465
    21865          95484, 12486
    Kind regards
    Kjetil Sandvik

    HI,
    Thank for your replies.
    We need to update all old orders for sure, but my idea was to use this query:
    Select CardCode, COUNT(Address2) From ORDR Where Docstatus <> 'C' GROUP BY address2, cardcode order by cardcode, address2
    The results will give me two lines for each customer and count the addresses, so then I know that the count of one of the lines must me changed. Let's say there is 20 orders with new address and 20 orders with old address, my intention was to manually change the 20 orders that is old. Instead of checking all 40, It would help alot to list all order numbers in a column beside in the query.
    BR
    Kjetil

  • Function Modules, for listing Cost centers Under a manager

    Hi All,
    1. Can any one please suggest me any Function Module available for listing the cost center under a manager, given only the Manager's username or pernr.
    2. And also the Function Group which has the collection of Function Modules which deals with operations and reporting on Cost centers from a Manager's Role (basically on budjet Monitoring aspects).
    Thanks and Regards,
    Girimurugan

    If this is the followup of the previous post (responsible person) and you wanted to get a list of cost centers based on that using a FM , i doubt that there is a FM available for that. You have to read the table to get the info.
    When you say manager, he could be a manager for a HR organisation but the cost organization may be different. in a typical set up it would be a cost center group (which will have set of cost centers under it) and this will be linked to a hr organization.
    All this is purely based on how cost center hierarchy (standard hierarchy) and hr organization maintained and how they are linked.
    Regards
    Raja

  • Alert is not working for mutiple times for list "select" function in sapui5 XML view

    Hello All,
    I am trying to open an alert for multiple times for list "select" function. But it's opening for only one time .
    Please find code below.
    View Part
    <List id="contactedit" select="somefunction">
        <CustomListItem id="custom1" type="Inactive" >
    <content>
    <Label text="this is label" />
    </content>
    </CustomListItem>
    </List>
    Controller Part
    somefunction: function(oEvent){
    alert("this is an alert");
    Thanks in Advance
    D.Mohanbabu

    I think I saw this question in stack overflow. And I answered it :-)
    I believe that it is because you can only one item in the list and once the item is selected, re-selecting it will not fire the event.
    Try adding more items to the list and select different items.
    Thanks
    -D

  • CVI IDE: Is it possible to see list of functions for faster navigation?

    Colleagues,
    Very simple question about CVI IDE.
    Is it possible to see whole list of functions for fast and convenient navigation, like in Micro$oft Visual Studio:
    When I have C code with more than 20-30 functions and 2000+ lines - its a very inconvenient to scroll up and down every time...
    I guess this feature should present in CVI, or I missing something? 
    How you working with relative large projects in CVI? 
    Thank you in advance,
    Andrey.

    CVI offers the Source Code Browser, which shows informations about files, functions, variables, data types and macros in your code. The code browser can be accessed in several ways: the easiest is to position over an element in the code and press Ctrl+F1: the lower part of the workbench will host the Source Code Browser area (though you can lately release this window to position it wherever you find it useful). There are several other ways to access these informations: I suggest you to look in the online help, topic Using LabWindows/CVI >> Writing Source Code >> Browsing Source Code
    CVI has several other ways of navigating in your application:
    Select a panel, menu or control callback and press Ctrl+Shift+U to go to the object in the UIR editor
    Right-click on an element in the UIR editor to go to its callback (if any)
    Select a function call in the code editor and press Ctrl+I to go to the function source
    Select a filename and press Ctrl+U to open it in an editor window
    ... and others I don't remember now! 
    Message Edited by Roberto Bozzolo on 05-07-2010 10:12 AM
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • FRM-41009:  Function key not allowed.  Press %s for list of valid keys.

    FRM-41009: Function key not allowed. Press %s for list of valid key.
    What is reason for this message, and how can we suppress it. Where should I set the system.message_level to suppress this message.

    The reason is you press a key that cannot be used, e.g. duplicate record cannot be used in enter query mode.
    You cannot suppress this message, even with message_level 25. If you code this for key-duprec, you will still get the message:
    :system.message_level := 25;
    duplicate_record;Forms intercepts the error at a very early stage. Even this didn't suppress the message:
    if :system.mode = 'ENTER-QUERY' then
      null;
    else     
      duplicate_record;
    end if;

  • Change structure for list editing of functional location

    What is the significance of change structure for list editing (t code il04) of functional location?

    just enter the functional locations you need to create and descriptions and save

  • Enabling the Export function for a distribution list in 'Private folders'

    Dears,
    Could someone please guide to the appropriate authorization that would allow the 'Export...' function for a distribution list created in a folder under 'Private folders' - Transaction : SBWP
    The option is dimmed, although the user used has the SAP_ALL profile.
    Thanks.
    Reda

    click file/publish settings/flash/actionscript settings and make sure frame 1 is set as the export frame.
    if that's already set, don't use test scene.

  • Func MD_MRP_LIST_API = MD06 list, but is there a function for MD04 ?

    Dear all SAP gurus.
    Func MD_MRP_LIST_API = transaction MD06
    ...but is there a function for MD04 ?

    Hi,
    Try FM MD_STOCK_REQUIREMENTS_LIST_API
    Cheers,
    Surinder

  • Report For list of material Master with PO text

    Hi all,
    I need a report whether it is available in Standard SAP or a customized, for List of Material Master with their PO text.
    If any one can help, please reply to this theard.
    Regards,
    Kapil Kulkarni

    To get the material number combined with the PO text you will need the help of an ABAP programmer.  The programmer can create a report for you using the function module READ_TEXT in the function group STXD.  The tables to use are:
    STXH - STXD SAPscript text file header
    STXL - STXD SAPscript text file lines
    The selection screen should have at least the following:
    OBJECT - STXH-TDOBJECT
    NAME - STXH-TDNAME
    LANGUAGE - STXH-TDSPRAS
    TEXTID - STXH-TDID
    You find the information for these fields by going to the PO text entry screen and displaying the header information under Goto -> Header.  For materials, the object is MATERIAL, the name is "material number", the language is "EN", and the text ID is BEST.  You can use this program to get long text in lots of places like information records, purchase order texts, etc.
    Hope this helps.

  • Crash on search function for HTML Help file (.chm) when connected to a Visual C++ application

    Crash on search function for HTML Help file (.chm) when
    connected to a Visual C++ application
    I use the RH_ShowHelp API command to connect a HTML Help file
    (.chm file generated by RoboHelp Word X 5) to my Visual C++
    application. My application is able to call up this HTML help file
    in context-sensitive mode and everything is working great in the
    Contents and Index panels EXCEPT when I click on List Topics (after
    I enter a KEYWORD for search) in the Search panel.
    I got an error that said “Unhandled exception in
    xxxx.exe.(HHCTRL.OCX):0xC00000FD: Stack overflow”
    I am able to execute this .chm file by itself and the search
    function works well in this case. I am using HHActiveX.dll that is
    created on 2/23/04. Is this the correct version?? Any advice what
    to do here??

    Hi agschin and welcome to the RH forums. The hhactivex.dll
    file is not used by the search function so you can rule that our.
    Have you tried recompiling and seeing if the problem still happens?
    You can also start the Bug Hunter feature in RH - View > Output
    View and then select the Bug Hunter button - and see if that throws
    up any clues.

  • Function module to give all partner functions for given customer

    Can anyone tell me function module name which gives all partner functions for a customer. For ex if we give customer number and sales area then it should give the list of all partner functions of this customer.
    I know 'CUSTOMER_PARTNERFS_GET' function module. But I want other than this.

    Hi,
    U can join VBAK and VBPA table and get the parrtners of the customer..
    Regards,
    Nagaraj

  • Functionality for Select and Save layout in a report output

    Hi,
    I had developed a report program containing several fields in the output and requires the Functionality for Select layout and Save layout in a report output.
    Please suggest.
    Thanks,
    Shariq.

    While calling the FM for List Display ( "REUSE_ALV_LIST_DISPLAY" or "REUSE_ALV_GRID_DISPLAY" ) set the Parameter I_SAVE for Setting the Layout and Selecting a different Layouts.
    The possible values for I_SAVE are "A", "U", "X" or others. Depending on the requiement you can set different values for the Parameter I_SAVE.
    ' ' = display variants cannot be saved
    Defined display variants (e.g. delivered display variants) can be selected for presentation independently of this flag.
    Changes can not be saved.
    'X' = standard save
    Display variants can be saved as standard display variants.
    User-specific saving is not possible.
    'U' = only user-specific saving
    The user can only save display variants user-specifically
    'A' = standard and user-specific saving
    The user can save a display variant user-specifically and
    as standard display variant. The user chooses in the display variant
    save popup.
    Reward points if helpful.

Maybe you are looking for

  • Unable to login Apex Admin

    11gR1 installed on Windows XP Pro SP3 I can get to the admin login page but when I try to login nothing happens. This seems like a common problem but the solution is not clear to me. I had 11g installed with Apex 3.0 so I upgraded it to 3.2.1 by usin

  • Sending mail Problem (Urgent Please)

    The following program mail coding program. I am in local System. Host is my server. But our Server (norton) firewall is enabled. I am not able to send any mail. Will you please tell me How to recover this problem or alter my coding. If anybody knows

  • Weird behavior by APD

    Hi Guru's I am observing very weird behavior in one of the process chain at APD step.APD step is getting failed due to lack of logs and due to this chain status is changed to failure in work-load automation screen.But without my intervention this ste

  • Planning time fence- MRP

    Hi Guys: Can I use Planning time fence if i am using MRP type PD? what are the settings i need to maintain for planning time fence and how it defined generally , is it a function of leadtime? Thanks Kodali

  • MAC OS X 10.4.7

    I have the latest iPhone OS (4.1) installed on my phone but I am wondering if MAC OS X 10.4.7 can be installed on the iPhone 3G. Is this possible? Message was edited by: kingwiggins