Merge-Sort (on paper) and Windows Error

As written in subject :/ Im Still working on merge-sort alghoritm (belive me, when you`re ill you`re not working as fast as you would like to :/). I use Dev-C++ compiler.

Well here`s the story:
1. My code compiled (yey!) but after inputing data it gave me unrealistic numbers (random numbers, so it have to be some kind of error with array)
2. I look for solution in web, after research i changed all arrays definition from f.e. 'Array[]' to '*Array[]'
3. Code compile.. but after giving the first "number" i get windows error "During the process program failed (...) Do you want to send information about this to Microsoft
4. I fall on the ground in demonic laughter and start to cry like small kid.

here`s current code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <conio.h>


int Merge(int *iTablicaA[], int iPo, int iSr, int iKo)
{

const int iDlug1=(iSr-iPo+1);
const int iDlug2=(iKo-iSr);
int *iTablicaB[iDlug1];
int *iTablicaC[iDlug2];

for(int i=0;i<=iDlug1;i++)
	{int u=iPo+i-1;
  	*iTablicaB[i]=*iTablicaA[u];
	 }
for(int i=0;i<=iDlug2;i++)
	{int u=iSr+i-1;
  	*iTablicaC[i]=*iTablicaA[u];}


int i=0;
int j=0;
for(int v=iPo;i<=iKo;v++)
{
	if(*iTablicaB[i]<=*iTablicaC[j])
	{
	*iTablicaA[v]=*iTablicaB[i];
 	i++;
	}
	if(*iTablicaC[j]<=*iTablicaB[i])
	{
	*iTablicaA[v]=*iTablicaC[j];
	j++;
	}
      }
return 0;					 					
}


int MergeSort(int *iTablicaA[] ,int iPo, int iKo)
{
 	if(iPo < iKo)
 	{
	 int iSr=(iKo+iPo)/2;
	 MergeSort(iTablicaA, iPo, iSr);
	 MergeSort(iTablicaA, iSr+1, iKo);
	 Merge(iTablicaA, iPo, iSr, iKo);
	 	   
	}
return 0;
}





int main()
{
int iPo;
int iKo;

const int iDlugosc=4;
int *iTablicaA[iDlugosc];


std::cout<<"Podaj dane JO!"<<std::endl;
for(int i=0;i<iDlugosc;i++)
std::cin>>*iTablicaA[i];

MergeSort(iTablicaA, iPo=0, iKo=iDlugosc-1);

for(int i=0;i<iDlugosc;i++)
std::cout<<*iTablicaA[i]<<std::endl;

getch();
return 0;
 	
}


Well, if it will help I can paste error log.
Last edited on
This won't compile under MSVC 2008:
1
2
3
4
const int iDlug1=(iSr-iPo+1);
const int iDlug2=(iKo-iSr);
int *iTablicaB[iDlug1];
int *iTablicaC[iDlug2];


It objects because of trying to create a const(ant) integer from variables whose values are not known until run time.
Okay, I removed all const. But it still leaves me with same error :/
Ah. Here we go.
Each of the elements of iTablicaA are pointers (for some reason known only to you). They are all pointing to unknown locations. The need to be initialized with new.
Topic archived. No new replies allowed.