|
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace GenericMergeSort
{
class MergeSort
{
/// <summary>
/// Sorts an array of Objects
/// IComparable - use 'CompareTo' to compare objects
/// where T : new() - need to create a new Type 'T' object inside the method
/// </summary>
/// <param name="X"></param>
public static T[] Merge_Sort<T>(T[] X) where T : IComparable, new()
{
int n = X.Length;
X = MegrgeSort_Internal(X, n);
return X;
}
/// <summary>
/// Internal method for sorting
/// </summary>
/// <param name="X"></param>
/// <param name="n"></param>
private static T[] MegrgeSort_Internal<T>(T[] X, int n) where T : IComparable, new()
{
// Define 2 aid Sub-Arrays
T[] A = new T[(n / 2) + 2];
T[] B = new T[(n / 2) + 2];
// Initialize the 2 Sub-Arrays with an infinite 'sorting parameter'
// Therefor, You must include a default ctor in your class
// which will initialize an infinite value - To the sorting parameter
// using 'where T : new()' here
for (int i = 0; i < A.Length; i++)
{
A[i] = new T(); ;
B[i] = new T();
}
// Recursive Stop-Condition, Sorting a Basic Array (Size 2)
if (n == 2)
{
int CompareValue = X[0].CompareTo(X[1]);
if (CompareValue > 0)
{
T tempT = X[0];
X[0] = X[1];
X[1] = tempT;
}
}
else
{
// The Sub-Arrays Size is Large than 2
if (n > 2)
{
int m = n / 2;
// Initialize the 2 Sub-Arrays (The first relevant values)
for (int i = 0; i < m; i = i + 1)
{
A[i] = X[i];
}
for (int j = m; j < n; j++)
{
B[j - m] = X[j];
}
// 2 Recursive Calling, Sorting Sub-Arrays
A = MegrgeSort_Internal(A, m);
B = MegrgeSort_Internal(B, n - m);
// Merging the Sorted Sub-Arrays into the main Array
int p = 0;
int q = 0;
for (int k = 0; k < n; k++)
{
{
int CompareValure = A[p].CompareTo(B[q]);
if (CompareValure == 0 ||
CompareValure == -1)
{
X[k] = A[p];
p = p + 1;
}
else
{
X[k] = B[q];
q = q + 1;
}
}
}
} // if
} // else
return X;
} // MegrgeSort_Internal
}
}
|
|
|
|
|
Few notes:
- The subject should be written using English language.
- Your code is not properly formatted.
- The code looks managed one, i.e. you have missed the right forum.
- There is no question at all.
BTW: Welcome at CodeProject.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
That's nice.
What was the question?
edit: Ninja'd!
|
|
|
|
|
can u please explain the problem, rather than just sending the code.
Величие не Бога может быть недооценена.
|
|
|
|
|
Hi, Im having MDI application.
In that all childframe have system menu.When i minimized it minimized to down.When maximized its get maximized to full screen.
But what i want is, if i press maximize the window should maximizd to limited width and height.
How can i do that?
I saw OnGetMinMaxinfo(),but i dont know wat parameter should use only for maximizing to certain height and width.
Pls help me.
Anu
|
|
|
|
|
I think you forget to check MINMAXINFO parameter of the OnGetMinMaxInfo(),
change the value of lpMMI->ptMaxTrackSize, then you can limit the width and height.
Величие не Бога может быть недооценена.
|
|
|
|
|
yes, i can set width and height of window.
But i want to set X and Y position of window.
How can i do that?
Anu
|
|
|
|
|
I'd like to create an application that is capable of hooking all input, ie mouse movement and keystrokes that the system recieves. No, I'm not writing a keylogger. If possible, I'd then like to stop those messages in their tracks, add them to a container, and then resend them later on after a specified time period in order to simulate an input delay.
My concern is with the hooking/blocking messages part. Is it possible to do this globally for the entire system?
|
|
|
|
|
Yes it is. Take a look at the function SetWindowsHookEx especially the values WH_KEYBOARD_LL and WH_MOUSE_LL
for the idHook parameter.
With this hooks you can capture every mouse and key input and you also will be able to stop forwarding these messages to the next "hooking" applications and the focused window.
Edit: Except the keystroke "ctrl-alt-delete". You will be able to capture this keystroke, but you will not be able to stop forwarding this keystroke!
Greetings
Covean
|
|
|
|
|
|
Hi, folks
I am thinking of writing a program which opens two files in one window. and these two files needs to be scrolled simulateneously.
(I have to put the scrollbar here as I have multiple views).
I plan to use such a structure
CMDIChildWnd, which has a scrollbar, and CSplitterWnd, its role is to change answer scroll related message such as OnSize, OnScroll.
CView, handles OnDraw, displays file.
CDocument, which has files info.
(I need to take advantage of OnOpenDocument)
the question is, when I load a file (which is handled by CDocument) either by OnOpenDocument() or some user defined open file function, how could I update CMDIChildWnd?
thanks in advance!
baum
|
|
|
|
|
You can call UpdateAllViews with a hind to update a particular view
Please refer for more details
[^]
Величие не Бога может быть недооценена.
|
|
|
|
|
thanks for the reply.
but updateview doesn't solve my problem, as scrollbar doesn't belong to a specific view (it belongs to CMDIChildWnd), and I need to update it too.
any idea?
thanks!
|
|
|
|
|
I think you dont need to update the CMDIChildWnd.
Величие не Бога может быть недооценена.
modified on Tuesday, January 19, 2010 12:19 AM
|
|
|
|
|
it is not, it is a CFrameWnd, container of CDocument and CView.
|
|
|
|
|
I think what you want to achieve is update two scroll views from the document?
i.e on update the two views simultanously?
Величие не Бога может быть недооценена.
|
|
|
|
|
exactly.
but I don't want to use two scrollbars, is it achievable?
|
|
|
|
|
I hope you want two Views, both derived from CScrollView? and using a single class.
If so then UpdateAllView is what you need.
Величие не Бога может быть недооценена.
|
|
|
|
|
i planed to use two views, and attached a scrollbar to CMDIChildWnd (i can't attach scrollbar to CDocument, as it is not a CWnd).
UpdateAllView only affect views, but not their container CMDIChildWnd.
If using scrollviews, I need to synchronize two scrollbars.....
|
|
|
|
|
I think you can get 2 CScrollViews and manage who is scrolling (the View is active) when you do the click in one of the scrolls, then from the document you get the new scroll position, give it to the other window using SetScrollPosition with pDoc->ActualPos_2 (assuming you made the click on View1) for the other one and call UpdateAllViews. Or just setting the scroll for both views where you need and call UpdateAllViews when opening a document.
Is that more or less what you wanted?
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nelek wrote: Or just setting the scroll for both views where you need
could you give a little bit more info?
are both views scrollviews or there is a scrollbar on top of them?
if both are scrollviews, how can I set scroll for both views? which class should handle scroll message?
thanks!
|
|
|
|
|
It would be using GetScrollPosition in the view that is getting scrolled with the OnScroll and sending it to the other view where you use it with SetScrollPosition before updating all views.
Yes, both views should be derived from CScrollView and each one would have its own scrollbar, but you synchronize one when moving the other
Here[^] is spoken about SetScrollPos and Here[^] about ScrollToPosition
If you manage the actual position of each View in the document, for instance m_pScrollPos_1 and m_pSCrollPos_2, you can call them in your OnDraw and move the actual position of the scroll for this view to the saved point. When you click on a scroll bar just save the new position in the document and call pDoc->UpdateAllViews.
It may have a bit delayment between the one and the other whilst synchronising. But it is a possibility
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
nelek
thanks for the detailed info.
|
|
|
|
|
You are welcome. I hope it works as you whish.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I'm not sure if this exactly fits your requirement, but it is possible to place two views derived from CScrollView into different panes of a splitter window and scroll them together.
You need to specify WS_VSCROLL when you create the splitter, otherwise you get a scrollbar for each pane instead of one that works them both.
I used WS_HSCROLL and WS_VSCROLL in a recent application to scroll around a matrix and get the row and column headings to scroll along with the body of the matrix. Like this (CMatrixSplitterFrame derived from CMDIChildWnd):
BOOL CMatrixSplitterFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
if (!m_SplitterWnd.CreateStatic(this, 2, 2, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL))
{
TRACE0("Failed to CreateStaticSplitter\n");
return FALSE;
}
if (!m_SplitterWnd.CreateView(0, 1, RUNTIME_CLASS(CKernelMatrixColHeadView), CSize(2000, CELL_YSIZE + CELL_INTER_GAP + CELL_INTER_GAP), pContext))
{
TRACE0("Failed to create second pane\n");
return FALSE;
}
Best Regards
Cliff Hatch
|
|
|
|