|
This[^] should help you choose one.
|
|
|
|
|
Do you actually need to sort them?
If the three arrays are already sorted and you just need to merge them then you could loop down them in parallel and copy the smallest value to the new array.
You need to increment the index for the copied value only and then loop around again.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
To find the best sort algorithm you must first get the value of each algorithm and then sort them...
|
|
|
|
|
Here's an implementation that does what I think you want.
Note: it uses Lists instead of Arrays. If you must use arrays then the output array must be big enough to hold all three input arrays.
Note: it relies on having a value (HIGH_VALUE) greater than any that can appear in any of the input arrays.
I've not done an analysis but don't think you can do it quicker. This goes through each array (List) only once. Any other approach probably needs multiple passes through the arrays.
using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
class Program
{
static List<int> listA = new List<int>();
static List<int> listB = new List<int>();
static List<int> listC = new List<int>();
static List<int> listOut = new List<int>();
static void Main(string[] args)
{
MakeSortedLists();
const int HIGH_VALUE = int.MaxValue;
int m = 0;
int i = 0;
int j = 0;
int k = 0;
int valueA = listA[0];
int valueB = listB[0];
int valueC = listC[0];
while ((valueA < HIGH_VALUE) || (valueB < HIGH_VALUE) || (valueC < HIGH_VALUE))
{
if ((valueA <= valueB) && (valueA <= valueC))
{
listOut.Add(listA[i]);
i++;
valueA = (i < listA.Count) ? listA[i] : HIGH_VALUE;
}
else
{
if ((valueB <= valueA) && (valueB <= valueC))
{
listOut.Add(listB[j]);
j++;
valueB = (j < listB.Count) ? listB[j] : HIGH_VALUE;
}
else
{
listOut.Add(listC[k]);
k++;
valueC = (k < listC.Count) ? listC[k] : HIGH_VALUE;
}
}
m++;
}
WriteOutList();
Console.ReadLine();
}
static void MakeSortedLists()
{
listA.Add(10);
listA.Add(11);
listA.Add(2);
listA.Add(1);
listA.Add(16);
listB.Add(5);
listB.Add(13);
listB.Add(7);
listC.Add(10);
listC.Add(6);
listC.Add(16);
listA.Sort();
listB.Sort();
listC.Sort();
}
static void WriteOutList()
{
Console.WriteLine("Posn Value");
Console.WriteLine("-------------");
for (int m = 0; m < listOut.Count; m++)
{
Console.WriteLine("{0,3} >> {1,4}", m, listOut[m]);
}
}
}
}
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
|
Hi, I would like to know if you can help me, I started working with Sharepoint about 2 weeks ago. Now, I work for a company that develops SP Sites etc. for other clients. I receiverd the task of creating an application with a user interface that backups what you choose to backup.
This must be a full on working application where you can choose the site, then subsites, custom web parts and custom master pages to backup. You must also be able to backup an entire site from the application.
I come from a web development background but have never worked with backups etc...so I have no clue where to begin.
I have spoken to my senior and he saiod that we would have to build everything from scratch and that we would not be able to use either the integrated Sharepoint.Administration.Backup or stsAdm.
Someone said I must look at the SPExport commands and to export the site as a template.
I cannot find sufficient info regarding backing up the site on the net as it is only the usual.
Have anyone done something like this before?
Please help
Jurie
|
|
|
|
|
I must build a program to solve 8-Puzzle with best first search algorithm , but i don't know how to do it.
You can build it in C# help me ( with source code)
Thanks!.
|
|
|
|
|
|
|
Im pretty sure its one of those 3x3 picture puzzles which has 8 parts to the image and you can slide one piece at a time into the epty square.
|
|
|
|
|
I generally see 4x4 with 15.
|
|
|
|
|
|
Dear all,
I got Timeout exception when reading from serial port.
how to overcome?
code:
// ports boudRate =115200, readtimeout=300 and writetimeout=300
private void btnRead_Click(object sender, EventArgs e)
{
OpenPort();
string str;
try
{
Thread.Sleep(1000);
str = _serialPort.ReadLine(); // exception occurs here
}
catch (Exception ex) { str = ex.Message; }
txtReadText.Text +=
string.Format("{0}{1}", "", str);
ClosePort();
}
|
|
|
|
|
Oh how lovely; we're so proud.
|
|
|
|
|
courtesy is a small thing but enough to make a big difference
|
|
|
|
|
Hi,
This is the expected behaviour. If _serialPort.ReadLine() is called and no data is available then the TimeoutException will be raised after 300ms. If you want ReadLine to block then don't set a timeout.
Alan.
|
|
|
|
|
Hi all,
I am working on a feature where in we can allow/disallow changing system time to any user. We can run this application from an administrator's account and set if a particular user can change system time or not. Even the administrator (who itself is logged on) itself can allow/disallow himself changing time.
While googling I found that there is some, The system user right SeSystemtimePrivilege that controls the ability to set the system time. I could not find how to complete my feature via the privilege SeSystemtimePrivilege using C#.
Can somebody help me how to that using c# (or even C++). Even if there is some other way of implementing this feature, please let me know.
Thanks in Advance
Best Regards
Aseem
|
|
|
|
|
If the machines are on a windows domain set the group policy in the Default Domain Controller Group Policy object (GPO) or if they are stand alone machines on a workgroup look in;
Administrative Tools --> Local Security Policies --> Local Policies --> User Rights Assignment --> Change the system time
From there set the users/groups that can change the system time, by default the groups that can change the system time are Administrators and Power Users.
|
|
|
|
|
|
i want get name tittle of WINDOW FORM from a handle of child form. for example : when i click mouse at a point of winform => i will get name tittle of that winform. i used function Getparent(..), GetAncestor(..) of method IntPtr, but it wrong.
wish help me.
thanks very much.
aazz
nothing
|
|
|
|
|
|
Hello everyone,
Would you please tell me if I have option to choose between for and foreach , whichone I should choose ? I know, foreach is better for Maintainance as I reduce the chance of error by misuse of index in for , But, if I use foreach, am I paying any cost for performance where it would be faster if I used for ? I need to decide for a performance critical application.
Thanks again.
|
|
|
|
|
for arrays and normal collections you will not be able to notice a difference in performance. You could however create your own collection with a very fast indexer and very slow GetEnumerator(), or vice versa. On purpose, that is.
And if you don't trust that, why don't you come up with a little test app?
|
|
|
|
|
I once attended an event where a presenter went to great and detailed lengths to show how for was superior to foreach. Of course he was oblivious to the fact that the audience ignored him after the first ten minutes and droned on for 45 minutes concluding that foreach should be removed from the .net framework.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
They should keep foreach and remove that presenter; it may be a fine topic for a white paper, not for a lengthy presentation IMO.
Anyway, I trust the majority of .NET programmers isn't going to come up with a decent way of measuring the difference; and in debug builds, it is much more advantageous to keep the exit condition simple, I once noticed a simple image manipulation slowed down by 33% due to x < myBitmap.Width in the inner for loop.
|
|
|
|