Checking two arrays...

This is a discussion on Checking two arrays... within the C++ Programming forums, part of the General Programming Boards category; How to make so that numbers in two arrays are placed in third array but sorted? I used bubblesort,but I ...

  1. #1
    Argo Argo_Jeude's Avatar
    Join Date
    Jul 2005
    Location
    Bihać, Bosnia
    Posts
    21

    Checking two arrays...

    How to make so that numbers in two arrays are placed in third array but sorted?
    I used bubblesort,but I have to do it without it.
    Exmpl.:
    (Elements in first and second array must be sorted from user)
    A=1,3,4,7,8
    B=1,4,5,6,9
    C=1,1,3,4,4,5,6,7,8,9

  2. #2
    Registered User
    Join Date
    Jan 2006
    Location
    Europe/Belgrade
    Posts
    78
    Algorithm called Merge sort does exactly this.

  3. #3
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    Well if first and second array are sorted then this will give you what you want (small example assuming total 10 elements):
    Code:
    int i = 0, j = 0, k = 0;
        
        while ( k < 10 )
        {
            if (arr1[i] < arr2[j])
            {
                arr3[k++] = arr1[i++];
            } 
            else
            {
                 arr3[k++] = arr2[j++];
            }
        }
    Cheers!

    - Micko
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  4. #4
    Registered User
    Join Date
    Jan 2006
    Location
    Europe/Belgrade
    Posts
    78
    Da svi mi batalimo engleski?

  5. #5
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    Haha, moze, ali mislim da se moderatorima nece svidjeti.

    It's ok with me, but I don't think moderators would love it.
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  6. #6
    Registered User
    Join Date
    Jan 2006
    Location
    Europe/Belgrade
    Posts
    78
    I said that, because this girl also speaks our language.

  7. #7
    Argo Argo_Jeude's Avatar
    Join Date
    Jul 2005
    Location
    Bihać, Bosnia
    Posts
    21
    Quote Originally Posted by karas
    I said that, because this girl also speaks our language.
    Nadam se da ne misliš na mene?!
    Zar nema pod kakvim opcijama da se stavi "MALE".

  8. #8
    Argo Argo_Jeude's Avatar
    Join Date
    Jul 2005
    Location
    Bihać, Bosnia
    Posts
    21
    Quote Originally Posted by Micko
    Well if first and second array are sorted then this will give you what you want (small example assuming total 10 elements):
    Code:
    int i = 0, j = 0, k = 0;
        
        while ( k < 10 )
        {
            if (arr1[i] < arr2[j])
            {
                arr3[k++] = arr1[i++];
            } 
            else
            {
                 arr3[k++] = arr2[j++];
            }
        }
    Cheers!

    - Micko
    Hvala!
    Pokušat ću!


    P.S.
    A ja mislio ja jedini Bosanac ovdje!


    TRANSLATION:

    Thanks!
    I'll try!


    P.S.
    And I (thinked?) I was only Bosnian here!
    Last edited by Argo_Jeude; 06-16-2006 at 06:59 AM.

  9. #9
    Registered User
    Join Date
    Apr 2006
    Posts
    2,012
    You could just use vectors and their sort meathod.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  10. #10
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    Quote Originally Posted by Argo_Jeude
    TRANSLATION:

    Thanks!
    I'll try!
    Uuf! for a moment there I thought you people were making fun of me.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking elements of an arrays
    By qwertysingh in forum C Programming
    Replies: 10
    Last Post: 02-11-2009, 09:57 AM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 08:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21