where's mistake ?

Please help

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
  #include<iostream>

using namespace std;

class OddEvenMergeSort{
public:
	int size;
	int a[];
public:
	void print(){
		for(int i=0;i<size;i++)
			cin>>a[i];
	}
	OddEvenMergeSort(){
		cout<<"shemoitanet masivis ganzomileba"<<endl;
		cin>>size;
		cout<<"shemoitanet masivis elementebi"<<endl;
		for(int i(0);i<size;i++)
			cin>>a[i];
		
	}
	~OddEvenMergeSort(){};
	void Sort(){
		oddEvenMergeSorti(0,size);
	}
	void oddEvenMergeSorti(int l,int n){
		if (n>1)
        {
            int m=n/2;
            oddEvenMergeSorti(l, m);
            oddEvenMergeSorti(l+m, m);
            oddEvenMerge(l, n, 1);
        }
	}
	void oddEvenMerge(int l, int n, int r){
        int m=r*2;
        if (m<n)
        {
            oddEvenMerge(l, n, m);      // even subsequence
            oddEvenMerge(l+r, n, m);    // odd subsequence
            for (int i=l+r; i+r<l+n; i+=m)
                compare(i, i+r);
        }
        else
            compare(l, l+r);
    }
     void compare(int i, int j)
    {
        if (a[i]>a[j])
            swap(i, j);
    }

    
};
int main() {
	OddEvenMergeSort A;
	A.Sort();
	A.print();
	return 0;
}
any idea?
Why do you think there is a mistake?
because it doesn't sorting. try to compile and u'll see
How do you know?

Your print() reads from cin rather that sending values to cout.

More severely, you never reserve any memory for the array. Therefore, when you do assign to array, you overwrite memory that is not yours.
Last edited on
I've changed cin to cout, but it's not working still, what else i need to change ?
Topic archived. No new replies allowed.