|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Merge array in VBI have 2 arrays like Dim x(2) As Integer Dim y(3) As Integer x(0) = 1 x(1) = 2 x(2) = 3 y(0) = 4 y(1) = 5 y(2) = 3 y(3) = 1 I want my final array as k(0) = 1 k(1) = 2 k(2) = 3 k(3) = 4 k(4) = 5 Does anybody know the open source code that I can use. thanks in advance abcd wrote:
> That's simply allocating a new array, copying the two into it and> I am looking for the open source for Merging 2 arrays in VB. .... sorting the result... You could, alternatively, sort each array and work through them comparing elements to form the merge, but the first is conceptually simpler and unless the merged array is quite large, possibly at least as fast. There are a zillion sort routines available a google search will find in VB source. "abcd" <a***@abcd.com> wrote in message It's not necessary to ask for "open source." If someone posts code here in a news:u5%23r9pB1FHA.1256@TK2MSFTNGP09.phx.gbl... >I am looking for the open source for Merging 2 arrays in VB. group or on the 'Net it's pretty much open unless otherwise specified, and even then you can read it, learn from it, and "do it yourself." Show quoteHide quote > I have 2 arrays like What you really mean is that you want to take two arrays, determine the > > Dim x(2) As Integer > Dim y(3) As Integer > x(0) = 1 > x(1) = 2 > x(2) = 3 > > y(0) = 4 > y(1) = 5 > y(2) = 3 > y(3) = 1 > > I want my final array as > > k(0) = 1 > k(1) = 2 > k(2) = 3 > k(3) = 4 > k(4) = 5 > > Does anybody know the open source code that I can use. UNIQUE values in them, and then create a new array with those values in a sorted order. Not exactly the plain-vanilla definition of "merge." Off the top of my head I recommend a two-step approach: Begin adding values from the first array to the new array, all the while checking the you're not adding a duplicate (this will require looping through the array a lot) and then doing the same with the second array. After that, sort it. You can find a bazillion (or is that brazillian?) examples of sorting out there. There may be an easier way involving hash tables, so look them up too. I just don't use them much myself. "Jeff Johnson [MVP: VB]" wrote: ....snip example of selective merge...> > "abcd" <a***@abcd.com> wrote in message > news:u5%23r9pB1FHA.1256@TK2MSFTNGP09.phx.gbl... > > >I am looking for the open source for Merging 2 arrays in VB. > What you really mean is that you want to take two arrays, determine the I hadn't noted the "incomplete" merge previously--if the two arrays are> UNIQUE values in them, and then create a new array with those values in a > sorted order. Not exactly the plain-vanilla definition of "merge." > > Off the top of my head I recommend a two-step approach: Begin adding values > from the first array to the new array, all the while checking the you're not > adding a duplicate (this will require looping through the array a lot) and > then doing the same with the second array. After that, sort it. You can find > a bazillion (or is that brazillian?) examples of sorting out there. > > There may be an easier way involving hash tables, so look them up too. I > just don't use them much myself. sorted initially one can minimize the number of loops through the second for the comparison as once once finds a match one can stop and then pick up from that point on the next. It also would eliminate the need to sort the new array. Or, one could simply merge, sort, then toss out the duplicates by finding the sequential elements which have a difference between adjacent values of zero. Which would be faster would depend on the sizes of the arrays and the charactreristics of the data. > k(0) = 1 If you really want the array to contain 5 elements only instead of 7, see > k(1) = 2 > k(2) = 3 > k(3) = 4 > k(4) = 5 "ReDim Statement" in MSDN. You could define it as 7 elements then shrink it to 5 later. Besides what others suggested, you could loop through X and Y arrays and find the smallest number and put it in K. Loop again and find a number bigger than the last one and so on. This way you don't have to sort the K array when you are done. Show quoteHide quote "abcd" <a***@abcd.com> wrote in message news:u5%23r9pB1FHA.1256@TK2MSFTNGP09.phx.gbl... >I am looking for the open source for Merging 2 arrays in VB. > > I have 2 arrays like > > Dim x(2) As Integer > Dim y(3) As Integer > x(0) = 1 > x(1) = 2 > x(2) = 3 > > y(0) = 4 > y(1) = 5 > y(2) = 3 > y(3) = 1 > > I want my final array as > > k(0) = 1 > k(1) = 2 > k(2) = 3 > k(3) = 4 > k(4) = 5 > > Does anybody know the open source code that I can use. > > thanks in advance > > > Thanks ALL
I took this approach arr1 and arr2 are say 2 arrays Algorithm 1. Filter arr2 from arr1 and copy the result into temp array. If both array are same simpy return arr2 or arr1. 2. copy all elements of arr2 and temp array to form my final array 3. apply bubblesort on my final array thanks abcd wrote: Show quoteHide quote > I am looking for the open source for Merging 2 arrays in VB. > > I have 2 arrays like > > Dim x(2) As Integer > Dim y(3) As Integer > x(0) = 1 > x(1) = 2 > x(2) = 3 > > y(0) = 4 > y(1) = 5 > y(2) = 3 > y(3) = 1 > > I want my final array as > > k(0) = 1 > k(1) = 2 > k(2) = 3 > k(3) = 4 > k(4) = 5 > > Does anybody know the open source code that I can use. > > thanks in advance
Subclass Help WM_NOTIFY
Efficient way to parse large files array loop alignment Finding files and/or folders BAS Module! Problem executing a DTS from a VB6 application after installing th "_files" folders and related folders Controlling location of form within form How to monopolize Windows in vb6 task bar? |
|||||||||||||||||||||||