Merging two linked lists of integers that are sorted

hey guys,
i need to write a method to merge two linked lists of integers that are sorted into ascending order. the results should be a third linked list that is the sorted combination of the original lists.
can someone help me start this? Basically, the method will be taking in two sorted linked lists of integers and merge them into one big sorted linked list.
Im just looking to get some algorithm ideas and maybe one or two lines of pseudocode to get me started.
thanks

i can't destroy the original lists so im gonna need
to create a new sorted list. then since both of the
lists im using are sorted, i'll just have to copy one
of them into the new list i created. Then i will get
an item from the unused list and search that node in
the new copied list and insert in appropriate
position using the two Nodes...example(prev and
curr).That can work. I'd probably do it by initializing a new list and compare the first items in each of the original lists, inserting the smaller in my new list and advancing to the next element in the original list from which I took the item, repeating the process until I copied each item from both original lists. Don't forget to take into account that you will reach the end of one list before the other.

Similar Messages

  • How to concatenate two linked lists?

    Can anyone help me with this? I'm stuck. I'm trying to concatenate two linked lists. I've created a method that adds a node to the beginning of a list and a second method to concatenate. My first method works, but not my second...
    First method:
    public static Node insertFirst(Node head, Node node){
              Node newNode = new Node();          // declare and initialize newNode.
              newNode = node;                    // store the new item in the new node.
              newNode.link = head;               // newNode.link points to the head.
              head = newNode;                    // update head to be newNode.
              return head;
         }Here is where I have my problem:
    public static Node mergeTwoLists(Node a, Node b){
              Node heada = a;
              Node headb = b;
              if(heada == null)
                   return headb;                    //if heada is null then returns list headb.
              else if(headb == null)
                   return heada;                    //if headb is null then returns list heada.
              else if(heada == null && headb == null)     //if both lists are null, returns null.
                   return null;
              else if(heada.link == null){     //only one element in heada.
                   headb = insertFirst(b, a);               // inserts the element in heada into headb.
                   return headb;
              }//end else if(heada.link == null).
              else if(headb.link == null){     //only one element in headb.
                   heada = insertFirst(a,b);               // inserts the element in headb into heada.
                   else {
                        mergeTwoLists(heada.link, headb);
                        return heada;
                   }//end else
              return heada;
              }//end mergeTwoLists method.I think in this method I'm only adding the nodes if there is only one node in one of the lists. But if there are more than one element in a list...I'm confused as to how to code the last else statement that contains the recursive call.
    Can someone help?
    Thanks
    aiki985

    Can't you just point the tail of A to the head of B?
    I don't think I'd do this recursivly at all. Use a
    while look to find the last node in A and then link
    it to whatever the first element in B is.
    while(A.next != null){
    A = A.next;
    A.next = B;
    Java that up a bit and check for nulls and it should
    work.o.k. thanks...let me try that. It does seem awkward recursively...
    aiki985

  • HT1918 How do i change my username to another when they both have accts with itunes one is on my computer and one is on my ipad? Two different e-mail address that are both mine....so how do i make one acct for both?

    How do i change my username to another when they both have accts with itunes one is on my computer and one is on my ipad? Two different e-mail address that are both mine....so how do i make one acct for both?

    If you selected open a new Apple ID account, go back a step and enter use existing Apple ID.
    You will have to set up a separate iCloud account or your iPads will mirror each other.

  • How to list all calendars that are shared to a specific user?

    Hi,
    Using Exchange Management Shell/Powershell, I want to list all calendars that are shared to a specific user 'myuser'. 
    I have tried different approaches; list all calendars for all users and then figure out which ones are shared to 'myuser', list all mailboxfolders for 'myuser' with path 'calendar' and sort out the shared ones, ... No luck so far.
    Anybody?
    babu

    Hi
    If you try this command:
    Get-MailboxPermission MyUser

  • How to know the list of reports that are in usage

    Hello,
    How to know the list of reports that are in use from the last 3 months by the users on Bw server.How basis team will help me in this regard?
    Regards,
    Anand.

    Hi,
    Pl look at following tables if you need any further detailed information
    Table Name  Use of the table 
    RSZELTDIR
    Directory of the reporting component elements
    RSZELTTXT  Texts of reporting component elements 
    RSZELTXREF  Directory of query element references .
    To get a list of query elements built on that cube.filter by: OBJVERS = 'A', INFOCUBE= [stage:cubename] 
    RSRREPDIR
    Directory of all reports (Query GENUNIID) .
    To get all queries of a cube.filter by: OBJVERS = 'A', INFOCUBE= [stage:cubename] 
    RSZCOMPDIR  Directory of reporting components.
    To get query change status (version, last changed by, owner) of a cube. 
    RSZRANGE  Selection specification for an element 
    RSZSELECT
    Selection properties of an element
    RSZCOMPIC
    Assignment reuseable component <-> InfoCube 
    RSZELTPRIO  Priorities with element collisions
    RSZELTPROP  Element properties (settings)
    RSZELTATTR  Attribute selection per dimension element 
    RSZCALC  Definition of a formula element 
    RSZCEL   Query Designer: Directory of Cells 
    RSZGLOBV
    Global Variables in Reporting 
    RSZCHANGES  Change history of reporting components
    Thanks and regards

  • T.codes to view the list of persons that are assigned to "activity"

    Hi Guru's
    Are there any transaction codes to view the list of persons that are assigned to u201Cactivity - personal assignment tabu201D in the project?
    Regards,
    Bha

    the same you can view from CJ20n , by clicking perticular activity--> click on person assignment tab.
    This can be true for all the netwrok maintenance txn.
    Regards
    Nitin

  • HT1420 where do i find the list of computers that are authorized in my account?

    where do i find the list of computers that are authorized in my account?

    Thanks for that.
    I downloaded the tool and something funny happens, i am trying to start the tool but I get an error saying: "The airport management utility requires airport 3.4 or later".
    I have airport 5.7 on osx 10.5 so of course nothing updates with system software update.
    Any one?

  • Where can I find a list of fonts that are native to Keynote, especially on the iPad? Thanks

    Where can I find a list of fonts that are native to Keynote on the iPad?
    Thanks

    This page has a lot of info:   iOSfonts.com
    I haven't tried it, but this app claims to let you install any true type font.

  • I've been given under warranty what us supposed to be a new iPhone 5. When I try and restore it from my iCloud it keeps asking me to sign in with two other Apple ID's that are not know to me. Why is this?

    I've been given under warranty what us supposed to be a new iPhone 5. When I try and restore it from my iCloud it keeps asking me to sign in with two other Apple ID's that are not know to me. Why is this?

    Adding to KC7GNM's remark (with which I agree), the iPhone 5 you received is very likely refurbished.  It is not brand new out-of-the-box, never before used.

  • How to know the List of Tables that are updated through a ABAP Program

    Hi,
    Is there a program or something that will help me to identify the List of Tables that are used in a ABAP program(ABAP Report, Transaction .... program) without debugging it or looking at the dictionary structure.
    I really need this urgently. Try to give me many methods as possible.
    Thkx
    Kishan

    Hi,
    I created a Z-transaction for my SE49 and debugged a little bit - it's not so fantastic any longer - just like the proposal of SE80 - DDIC list.
    SE49 (and I guess similiar functions, too) just scan the source code for a list of key words: tables, select, update, insert, modify, export, import.
    But very (very!) often updates are encapsulated into function modules - and here this technical cross reference (just like SE80 DDIC list) is of no help.
    So a SQL trace (or runtime analysis) is still the best option to get a complete list. Still these tools just analysis one process - if in other circumstances more tables are involved, can't be judged.
    E.g.:
    - creating one new entry: 1 table
    - changing existing entry: 2 accesses to 1 table + log table
    Regards,
    Christian

  • Merging two SharePoint lists

    Hello !
    I have 2 SharePoint lists for years 2013 and 2014. I want to merge them and then pull the merged list into PowerPivot. I appreciate any help for that. I don't want to have 2 lists in PowerPivot, so I was wondering if there is anyway that I can merge these
    2 SharePoint lists?
    --update--
    I need to have live connection between the lists.  It means I want to have an automated process in place that can merge two lists once I pulled them into PowerPivot without any manual process of merging the lists.

    I don't know what rights you need to do this, but go to each site and do the following instructions:
    Click on Site Actions
    Click Site Settings
    Click Manage All Site Settings
    Under the Site Administration Group, click Content and Structure
    A window comes up that looks like Window's File Manager. You are in the current site, but you can see that you can browser to other sites in your site collection from the left panel.
    Locate the list you want to copy items from and click the name. You will see all the items, or at least in pages of 100.
    Change the paging quantity from 100 to 1000 in the top right, where it says "Show 100".
    Select all the items you want to copy. There's an icon that looks like a stack of papers, to select all items on this page.
    Click Actions in the toolbar, then click "Copy...". A dialog will come up of the current site collection.
    Choose the destination then, click Ok.
    Repeat this until you're done copying all items from the list.
    Be patient while the copy process completes, then switch to the other 49 sites. You cannot copy from one site collection to another. You can copy between
    subsites or sister sites. If you can't see the Content and Structure link in the Site Settings page, use the 12 hive URL: http://sitecollection/_layouts/sitemanager.aspx You'll
    have the items copied in no time without the help of IT/development.
    Courtesy links
    http://stackoverflow.com/questions/17956557/combine-multiple-sharepoint-lists-into-one
    https://www.nothingbutsharepoint.com/2012/05/11/how-to-link-two-lists-and-create-a-combined-view-in-sharepoint-2010-aspx/
    http://sharepoint.stackexchange.com/questions/34198/combining-multiple-lists-into-one
    https://social.technet.microsoft.com/Forums/sharepoint/en-US/bcd2f069-ceec-42df-8989-a03e0cb017f3/to-join-two-sharepoint-list-having-a-common-colomn-without-using-joins?forum=sharepointgeneralprevious
    please 'Propose as answer' if it help you, also vote this as helpful if you like this reply.

  • List of formulas that are allowed in PLD

    Hi,
    i am an ABAPer & new to this SAP B1 env.
    is there any document/link that gives the list of formulas (along with syntax) that are allowed in PLD ?
    actually i have to print "No. of days delayed" (Run Date - Due Date) in Customer Statement letter.
    i tried entering the formula as Field_167 - Field_036 but i get only 0 (zero) even though there is diff in dates.
    i tried with datediff(DAY, Field_036,  Field_167) and got the error : Errors were found in the formula"
    what is the exact syntax to calculate elapsed number of days?
    to check for a condition also, it seems, we need to have additional UDFs & establish the dependencies to get what we want, instead of having a straight forward "if" OR "case" statement.
    working with SAP B1's tools (e.g. PLD) is like doing a surgery with kitchen knife! (sorry, if i have hurted anyone's feelings
    if anyone can give a list of formulas (along with exact syntax) that are allowed in PLD it will be of great help to people like me.
    Thanks & Regards,
    Raghu Iyer

    well, i solved my 'Days Overdue' OR 'elapsed days' in a crude way (see my method given below), if anyone has got a better & accurate method, please do share it with the beginners like me.
    available values :
    Field_167 is the 'Ageing Date' (a text field in Page Header Area)
    Field_036 is the 'Due Date' (a text field in Repetitive Area)
    requirement :
    to print 'Days Overdue' (Field_167 - Field_036 + 1) along with 'Due Date' in repetitive area.
    even after browsing through this forum & other some materials provided in SAP Service Market place, i could not find a function/method to get the elapsed number of days between two dates. so, i went about in around about way to arrive at the 'Days Overdue'. given below is my method that gives the elapsed days, though a close one but not accurate, since i took a month as 30 days. otherwise, this seems to work fine, i need to check it out thoroughly.
    in the repetitive area:
    defined a new hidden field Field_187 as Formula : (Month(Field_167)*30)+Day(Field_167)
    defined a new hidden field Field_188 as Formula : (Month(Field_036)*30)+Day(Field_036)
    defined a new field Field_189 for 'Days Overdue' as Formula : ((Year(Field_167)-Year(Field_036))*365)(Field_187-Field_188)1
    Regards,
    Raghu Iyer

  • How to create two linked lists (Master/Detail or Parent/Child)

    I need to create a couple of related lists in a Master/Detail approach. Users are supposed to choose one "Master" Option, and "Detail" column should be refreshed to display only the items that are strictly related to the chosen option
    in "Master". Any posible solution?
    Thanks in advance.

    One option is to connect two web parts. This will give you option button for your master list web part and based on the value selected your results will be filtered in the detailed list web part. Here is the example. Though it is for SP 2010 it should work
    the same in SP 2013.
    http://sarahlhaase.wordpress.com/2012/05/21/connecting-web-parts-with-a-selector-and-a-detail-pane-sharepoint-2010-version/
    Second option is with some customization using Jquery.
    http://summit7systems.com/creating-a-parentchild-list-relationship-in-sharepoint-2013/
    Amit

  • HT4009 Is there a 'black-list' of Apps that are basically fraudulent that one can consult and be warned of what Apps to avoid?

    Is there a black-list of Apps being sold in iTunes that are basically fraudulent or a swindle that users can consult in order to be forewarned to avoid the said Apps? I

    There are no black lists and the apps that are free but offer in-app purchases are not fraudulent.  They do allow you to play without paying money, however there are likely to be many options and oppotunities to purchase items within the game.
    If you feel that a application is truly fraudulent because it makes statements or promises that are not true or it has charged you money without your consent, then you need to contact iTunes Store Support to let them know.

  • How do I merge two buddy lists?

    Just downloaded Chax. I love the tabbed chat feature, but I want to integrate my two Buddy Lists. How do I do that? Does Chax offer that?

    Hi heatgrave,
    I am not aware of any quick way to do this.
    Make sure each Buddy has a Real name or Nickname added to the iChat Address Card. (click once on a Buddy and then use Apple key and i together (Get info). Then select the Address Card).
    This adds the Buddy to you Address Book.
    Names can be dragged from the Address Book to iChat.
    9:55 PM Wednesday; January 24, 2007

Maybe you are looking for