|
Even on a list of 1000 things, a bubble sort will be pretty quick. Its when you start hitting millions (well, at least hundreds of thousands) that you'll notice the difference.
A quick google search found this page[^] which should provide some useful reading for you.
|
|
|
|
|
Ooh that is some useful reading, so for my problem the bubble sort would work just fine, and get back the results fairly quickly, ah.
But i might just use the quick sort anyways.
|
|
|
|
|
The idea of the bubble sort is the easiest of all, but this sort is almost always the slowest sort of all. It should be replaced, at the very least, with an Insertion or Ripple sort (which are just as easy to program) for small lists, and with one of the faster sorts, such as Shell sort, for longer lists. The only good place to use bubble sorts is if the list to be sorted is already essentially sorted!
- Ashish
Time flies like an arrow;
Fruit flies like a banana.
Ashish Derhgawen - http://ashishrd.blogspot.com
|
|
|
|
|
Ashish Derhgawen wrote: he only good place to use bubble sorts is if the list to be sorted is already essentially sorted!
Selection/insertion are still faster there.
The only place for a bubble sort is on an exam when you're not allowed to a canned Sort() function, but instead have to write your own.
|
|
|
|
|
Bubble sort takes O(n²) time. Do yourself a favor and get to know a O(n log n) sorting algorithm. I think merge sort is the simplest to learn. Small comparison:
For 100000 elements: Bubble sort takes 800 seconds (that's 13.3 minutes) while merge sort only takes 0.6 seconds.
Quick sort is a even faster than merge sort (but not very much), but hard to do right.
|
|
|
|
|
Oh, and since this is the C# forum and not the Algorithms forum:
Remember there are built-in sorting functions in the .NET Framework which implement quick sort. If you have an array, just call Array.Sort(myArray), on a List<t>, call myList.Sort().
Both sorting methods have overloads that take a custom comparison function in case you want to sort by a different criteria than the default for the data type is.
|
|
|
|
|
Daniel Grunwald wrote: Remember there are built-in sorting functions in the .NET Framework which implement quick sort.
As far as I know first a quicksort is used to "divide and conquer", but for sublists with <=7 elements the insertion sort is used. That's at least the case in the C++ STL.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Greeeg wrote: As far as I know first a quicksort is used to "divide and conquer", but for sublists with <=7 elements the insertion sort is used. That's at least the case in the C++ STL.
Interesting. Is that an empirical point beyond which the recursive overload becomes larger than the savings of nlogn vs n^2.
|
|
|
|
|
Yeah something like that. This explains it a bit better.
The June 2000 SGI C++ Standard Template Library stl_algo.h implementation of unstable sort uses the Musser introsort approach with the recursion depth to switch to heapsort passed as a parameter, median-of-3 pivot selection and the Sedgewick final insertion sort pass. The element threshold for switching to the simple insertion sort was 16.
Okay, a bit different
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
My project is CMat, with RderTable in RderDataSet with
columns Descr and Price. OrderEntryForm and ViewOrderForm with dataGridView1 in OEForm and reportViewer1 in VOForm.
reportViewer1 uses report1.rdlc with table1.
OEForm generated rderDataSet and rderTableBindingSource & VOForm generated RderDataSet and RderTableBindingSource when fields dragged from DataSource Window. I click a Button in OEForm to ShowDialog VOForm. I tried to insert
RderTableBindingSource.DataSource = rderTableBindingSource.DataSource or rderDataSet.RderTable
before, this.reportViewer1.RefreshReport in VOForm_Load
- error "does not exist in current context"
Please help me view the active Order entry table filled by rderDataSet.ReadXml, in a reportViewer1.
Ramith Sivanarain
-- modified at 9:52 Thursday 12th October, 2006
|
|
|
|
|
Hi everybody!
I want to scan the ports on my computer, and I'm looking for the right class to do that.
any clues please?
thanks!
|
|
|
|
|
Hi!
I'm not sure about this but you could try to do it like this:
<br />
System.Net.Sockets.TcpClient myclient = new System.Net.Sockets.TcpClient();<br />
for (int i = 0; i < 65535; i++)<br />
{<br />
try<br />
{<br />
myclient.Connect("localhost", i);<br />
}<br />
catch<br />
{<br />
}<br />
}<br />
This method is obviously not the best because it uses a try..catch statement and it will also throw an exception if a particular port is blocked by another application.
To get around this issue you will have to extend the exceptionhandling massively.
That's how i would do it but as already mentioned i'm pretty unexperienced...
Good luck,
mik
|
|
|
|
|
Hi
I thought about this method, but its really not an efficient one.
thanks alot anyway!
|
|
|
|
|
Good Morning,
i have a problem!
i have a form with a TextBox and DataGrid.
i fill a DataGrid with DataBase records
and when i select a record in DataGrid i show it in textbox!
But i want to type a character at textbox and automatically locate the record in DataGrid (Partial key search)!
Thanks a lot!
|
|
|
|
|
Hello,
you can use a Filter on the Datagrid:
At first, you must create a DataView on your table.
DataView dv = new DataView();
dv.Table = MyDataSet.Tables["Suppliers"];
Then you can set the RowFilter like this : dv.RowFilter = "City = 'Berlin'";
You can use different FilterOptions, like in SQL : dv.RowFilter = "Name = 'S%'";
S% -> All that begans with S
( Naturally it seems in you case like this : dv.RowFilter = "Name = '" + textbox.Text + "%'";
Then you choose the DataView as DataSource of the Grid
There are propably some errors im my example, but the logic is right
( I used it before 1 year and i still don't have the code here )
Good luck
|
|
|
|
|
thanks dude!!
i'll try it "Filter on the DataGrid"!!
if i find out anything else i´ll call you again!!!
cya!
|
|
|
|
|
can i enter a command line argument after installing application from clickonce technology
|
|
|
|
|
A command line argument to the click once application? Yes, but you have to take some steps to allow command line arguments. When publishing the ClickOnce app from Visual Studio, go into your project settings page, Options, then enabled "Allow URL parameters to be passed to your application". You can then pass parameters via a query string:
www.myclickonceapp.com/theapp.application?someParam=5
|
|
|
|
|
Hi,
I'm currently in the process of planning a Server-Client application and evaluating whether Remoting is a good way to go. I've already read some MSDN articles about remoting and also looked at some of the remoting articles here but there are still some questions:
1. Is the server side knowing which clients are currently connected?
What I currently know is that connected clients can instaniate and fetch objects from the server. Calls on functions on those objects may either be run locally or on the serevr side. Is it possible to determine on the server side which clients currently hold those objects? I know I could define functions so that clients can explicitely notify their connection or disconnection but I think about lost connections or client side crahes where no explicit call is possible anymore.
2. Can the server send messages to the clients?
In the examples I have investigated so far (mostly chat apps) the clients regulary poll for new data from the server. Is there a possibility that the server directly calls functions in all connected clients?
3. When a client makes a call in the server does this call create server side a new thread in which this call is processed? Is this the same for every call coming from the same client?
Robert
|
|
|
|
|
Robert Rohde wrote: 2. Can the server send messages to the clients?
In the examples I have investigated so far (mostly chat apps) the clients regulary poll for new data from the server. Is there a possibility that the server directly calls functions in all connected clients?
Yes, in fact, you can use the normal event mechanism to do that i.e server exposes an event and clients subscribe to it. There are a few gotchas though, like firewalls preventing incoming traffic. You would also have to make some config changes to allow clients to recieve calls (See TypeFilterLevel[^]).
Robert Rohde wrote: 3. When a client makes a call in the server does this call create server side a new thread in which this call is processed? Is this the same for every call coming from the same client?
Last I checked, remoting calls come in on a IOCP Thread. The .NET ThreadPool has a 1000 of them by default, in addition to the normal 25 threads per processor.
|
|
|
|
|
|
|
Hello,
I have written an application in c# and would like to set a shortcut key to start the application.
I would like to use ctrl+shift+h to start the application.
Also I would like the user to be able to change this shortcut key.
Can anyone help.
Thanks
cjm
|
|
|
|
|
you need to use system wide hook so that the os can intercept any key strokes and determine if it matches the ones you want then you process them and fire the application.
then you need a shortcut editor to change the shortcut by listening to the keys the user enters and rather than opening the program, assign it as the hotkey.
below is a class i found and adapted to suit my needs ( the class didn't have any copyright info in it and i can't remember where i found it, so i apologize if anyone is offended, although i did modify and improve it extensively )
DO NOT USE THIS CODE FOR MALICIOUS ACTIVITY, ELSE I WILL BE *VERY* DISSAPOINTED, AND YOU MAY GO TO HELL FOR IT!
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace GlobalKeyHook
{
public class KeyboardHook : IDisposable
{
#region Hook-dlls
[DllImport("user32", EntryPoint = "SetWindowsHookExA")]
private static extern int SetWindowsHookEx(int idHook, KeyBoardCatcherDelegate lpfn, int hmod, int dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto,
ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
private static extern short GetKeyState(int keyCode);
[DllImport("user32", EntryPoint = "MapVirtualKey")]
private static extern int MapVirtualKey(int wCode, int wMapType);
[DllImport("user32", EntryPoint = "CallNextHookEx")]
private static extern int CallNextHook(int hHook, int ncode, int wParam, KeybHookStruct lParam);
private const int
WH_KEYBOARD = 2,
WH_KEYBOARD_LL = 13;
[DllImport("user32", EntryPoint = "UnhookWindowsHookEx")]
private static extern int UnhookWindowsHookEx(int hHook);
#endregion
private bool m_DisableHooking = false;
public bool DisableHooking
{
get { return m_DisableHooking; }
set { m_DisableHooking = value; }
}
public KeyboardHook()
{
kbcatcher = new KeyBoardCatcherDelegate(KeyBoardCatcher);
keybhook = SetWindowsHookEx(WH_KEYBOARD_LL, kbcatcher,
Marshal.GetHINSTANCE(typeof(KeyboardHook).Module).ToInt32(), 0);
if (keybhook == 0)
throw new ExternalException("Error: " + Marshal.GetLastWin32Error().ToString() + "\r\nCould not hook keyboard");
}
public KeyboardHook(bool AddModifierData)
: this()
{
this.AddModifierData = AddModifierData;
}
#region Dispose
private readonly int keybhook;
private bool disposed;
public void Dispose()
{
if (!disposed)
{
UnhookWindowsHookEx(keybhook);
GC.SuppressFinalize(this);
disposed = true;
}
}
~KeyboardHook()
{
Dispose();
}
#endregion
private struct KeybHookStruct
{
public int vkCode, scanCode, flags, time, dwExtraInfo;
}
private delegate int KeyBoardCatcherDelegate(int code, int wparam, ref KeybHookStruct lparam);
public static bool CheckKeyPressed(params Keys[] keys)
{
for (int i = 0; i < keys.Length; i++)
if (!CheckKeyPressed(ref keys[i])) return false;
return true;
}
public static bool CheckKeyPressed(ref Keys key)
{
return CheckKeyPressed((int)key);
}
public static bool CheckKeyPressed(int vkey)
{
short ks = GetKeyState(vkey);
Console.WriteLine(ks);
return ks == 1;
}
public bool IsKeyPressed(Keys key)
{
return CheckKeyPressed(ref key);
}
public bool AreKeysPressed(params Keys[] keys)
{
return CheckKeyPressed(keys);
}
private const int HC_ACTION = 0;
[MarshalAs(UnmanagedType.FunctionPtr)]
private KeyBoardCatcherDelegate kbcatcher;
public event KeyEventHandler
KeyDown = null,
KeyUp = null;
private const int
wpKeyDown = 256,
wpKeyUp = 257;
public bool AddModifierData = true;
public readonly Keys[] Modifiers = { Keys.Alt, Keys.Control, Keys.Shift };
private int KeyBoardCatcher(int hookcode, int wparam, ref KeybHookStruct lparam)
{
if (HC_ACTION == hookcode)
{
if ((wparam == wpKeyDown && KeyDown != null)
|| (wparam == wpKeyUp && KeyUp != null))
{
try
{
Keys k = (Keys)lparam.vkCode;
if (AddModifierData)
k |= Control.ModifierKeys;
KeyEventArgs e = new KeyEventArgs(k);
if (wparam == wpKeyDown)
KeyDown(this, e);
else
KeyUp(this, e);
if (e.Handled) return 1;
}
catch { }
}
}
return CallNextHook(keybhook, hookcode, wparam, lparam);
}
}
}
in your main init it like this
KeyHooker keyhooker = KeyHooker.Instance;
when you want to disable it so you can process the keys in the 'key editor' or 'key assignor', do this
KeyHooker.Instance.DisableHooking = true;
then re-enable them on form close or after the hot key is decided with this
KeyHooker.Instance.DisableHooking = false;
hope that helps
g00fy
|
|
|
|
|
cheers dude. thats a lot of code but I will give it a go.
atb
cjm
|
|
|
|