|
Farraj wrote: temp = index[a[j+1]];
index[a[j+1]] = index[a[j]];
index[a[j]] = temp;
you should drop all the a[]'s here, you really want to swap two index entries, no more, no less.
|
|
|
|
|
thank you.
i've got it working but the array is sorted from the minimum index to the maximum, how can i fix it the oppisite way?
this is the code so far..
if(a[j]>a[j+1])
{
temp = index[j+1];
index[j+1] = index[j];
index[j] = temp;
}
another thing.. you've mentioned something about initializing the array from 0->N-1, ive done that while i know what size my array is.
what if the size is unknown N, how can i initialize it to be from 0 to N-1? should i make another loop to initialize it or there is some other way?
Thanks a lot for everyone's help
|
|
|
|
|
Farraj wrote: what if the size is unknown N
you create and initialize the index array after the value array is known, so you do know N.
Farraj wrote: how can i fix it the oppisite way?
if you were to understand what you have done so far, you wouldn't be asking such question...
|
|
|
|
|
I did understand Luc
thank you for your help
this is my code for now
#include <stdio.h>
#define N 5
void main()
{
int a[N];
int index[N];
int i,j,temp;
int count=0;
for(i=0; i<N; i++)
{
scanf("%d",&a[i]);
index[i]=count++;
}
for(i=0; i<N; i++)
{
for(j=0; j<N-1; j++)
{
if(a[j]>a[j+1])
{
temp = index[j+1];
index[j+1] = index[j];
index[j] = temp;
}
}
}
for (i = 0; i < N; ++i)
{
printf("%d ",index[i]);
}
flushall();
getchar();
}
i think it should work perfectly, its just it doesnt !! though it looks exactly how it should be
can u run it and tell me where is the problem please?
Thanks.
|
|
|
|
|
oh im sorry i guess i forgot to compare with a[inde[]]
now its working perfectly
thank you a lot SIR
|
|
|
|
|
Farraj wrote: if(a[j]>a[j+1])
is obviously wrong. you need to look at the a value "through the index array".
try
if(a[index[j]]>a[index[j+1]])
that is what you have to pay for the fact that you never actually move the a values around; all you do is change the index values.
You have had the test correct a while ago...
|
|
|
|
|
Yep yep yep for some reason i replaces that line by mistake lol
thank u a lot i appreciate ur help
|
|
|
|
|
|
I want to fully draw combobox control by myself, not only the list items. I searched but only found some demos about how to custom draw its subitems. But I really want to draw the edit, arrow button and listbox of the combobox completely. So, is there any example or idea?
Regards
|
|
|
|
|
I'd say, subclass the combo box and all the controls inside it (list, edit...) and handle WM_PAINT, WM_ERASEBKGND and somesuch. Or write your own complete control from scratch.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
You means, just subclass all its three subitems?
but if use its ownerdraw property?
|
|
|
|
|
I don't understand what you mean...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
I meant, how to use WM_MEASUREITEM and WM_DRAWITEM messages handler if i subclass its edit, button and listbox.
|
|
|
|
|
anyone of you have examples of graphs opencv segmentation, thanks
|
|
|
|
|
Separate the different color channels or segment the image into different color blobs?
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
What exactly is the problem? You don't know how to do color segmentation or you don't know to use OpenCV to do color segmentation?
Here[^] is a simple algorithm for color segmentation using HSV color space. For the problem with OpenCV you will have to be more specific.
-Saurabh
|
|
|
|
|
Are you suppose to collect all the colors uses by an image & put them into different segment accordingly?
If so, then open image into binary format & create four matrix of R,G,B & O (offset values) considering each of them as a segment. Put each RGB values into corresponding martix. Thats all I guess.
If your requirment is somthing else, then im
|
|
|
|
|
Hi All,
I am developing one application that create Internet Shortcut and it is working fine. But in some system it fails to save and Send error message "Access Denied". How to resolve this issue??
Thanks in advance.
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
Firstly i think u should debug your application on those machine, isnt it possible?
well check the below point to.
Check whether ID_IPersistFile is defined as 0000010b-0000-0000-C000-000000000046.
Величие не Бога может быть недооценена.
|
|
|
|
|
Hii, Thanks for ur reply...
yae it is possible i will check it but what does it mean if id is 0000010b-0000-0000-C000-000000000046??
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
Hi,
I am trying to use a Dialog as a Control in another Dialog. MFC Documentation vaguely suggests this as something that can be done (you can set the 'Control' Property in the dialog you want to use as source. The help files and examples become 'thin on the ground' when it comes to how to actually do this. Anybody any ideas?
Bram van Kampen
|
|
|
|
|
I do this a lot in one of my older applications. Suppose your two dialogs are IDD_MAIN and IDD_SUB, with corresponding MFC classes CMainDlg and CSubDlg. The resource for the sub dialog should have the following styles set: Border=None, Style=Child, and Control=True. This will let the sub dialog visually blend into the main dialog.
The basic approach is to use the sub as a modeless dialog whose parent is the main dialog. You then need something like this to get it going:
BOOL CMainDlg::OnInitDialog()
{
CSubDlg *sub = new CSubDlg(CSubDlg::IDD,this);
sub->Create(CSubDlg::IDD,this);
sub->MoveWindow(10,10,100,100);
sub->ShowWindow(SW_SHOW);
} Obviously, there are lots of ways this needs to be fancied up. You probably want this sub-dialog positioned relative to other controls. What I usually do is place a static control where I want the sub-dialog to go, and then position the sub-dialog using logic like this:
CSubDlg *sub = new CSubDlg(CSubDlg::IDD,this);
sub->Create(CSubDlg::IDD,this);
CRect sub_rect;
GetDlgItem(IDC_SUB_DIALOG)->GetWindowRect(&sub_rect);
ScreenToClient(&sub_rect);
GetDlgItem(IDC_SUB_DIALOG)->DestroyWindow();
sub->SetDlgCtrlID(IDC_SUB_DIALOG);
sub->MoveWindow(&sub_rect);
This logic does several things: it gets the position of the static control, destroys it, and then places the sub dialog in the same position. As a final refinement, it assigns the control ID to the sub dialog.
Note that, for completeness, you really should save the pointer to the sub dialog instance as a member of the main dialog class, and delete it in that class' PostNcDestroy().
|
|
|
|
|
|
Glad to be of help .
|
|
|
|
|
Hi! I have to do a project for my studies. It is a insertion algorithm.
I'm reading data from file with using vector.
then I'm copying vector to a normal array (the reason is simple: I don't know how to send vector to function, but this is not a main problem).
After copying, I'm sending (with using pointers) array to sorting function.
Everything is good, algorithm is working but! (yep, there is always but...
When I save a lot of data to file, program just after start crashes.
The numbers in file are written in that way:
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
So there are 40 numbers in one line. I have 4.000 lines, so after simple math we have 160.000 numbers. The main problem: when I add some new numbers for example 40.000 program crashes
I must have more numbers because the task is to compare few sorting algorithms with minimum 15 minutes of sorting. (160.000 digits is sorting in ~1 minute)
Here's the code. Maybe it is poor written, but I did my best.
#include <QtCore/QCoreApplication>
#include <iostream>
#include <time.h>
#include <iomanip>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
void insertion_sort(int *wsk, unsigned long size);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
vector <int> array_vector;
ifstream plik ("numbers.txt",ios::in);
unsigned long single_number;
while(plik >> single_number)
{
array_vector.push_back(single_number);
}
int array_nonsorted[array_vector.size()];
for (unsigned long a = 0; a < array_vector.size(); a++)
{
array_nonsorted[a] = array_vector[a];
}
time_t start,end; double long dif;
cout << "START\n";
time(&start);
insertion_sort(array_nonsorted,array_vector.size());
time(&end);
cout << "STOP\n";
dif = difftime(end,start);
cout << "Array sorted in " << setprecision(5) << dif << "sec"; dif = dif/60; cout << " = " << dif << "minutes";
return a.exec();
}
void insertion_sort(int *wsk, unsigned long size)
{
int tab_sorted[size];
for(unsigned long i = 0; i < size; i++)
{
tab_sorted[i] = wsk[i];
}
for (unsigned long a = 1; a < size; a++)
{
if (a == 1)
{
if (tab_sorted[0] > tab_sorted[1])
{
unsigned long temp = tab_sorted[0];
tab_sorted[0] = tab_sorted[1];
tab_sorted[1] = temp;
}
}
else
{
for (unsigned long b = 0; b <= a-1; b++)
{
if (tab_sorted[a] < tab_sorted[b])
{
unsigned long temp = tab_sorted[a];
for (unsigned long c = a; c > b; c--)
{
tab_sorted[c] = tab_sorted[c-1];
}
tab_sorted[b] = temp;
}
}
}
}
}
So why the program crashes? I don't have a clue Something with memory (but I have 3.0GB and OS works normally when program is starting). Please help!
Luk.
|
|
|
|