bubble sort and pointers

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
80
81
82
#include <cstdlib>
#include <iostream>

using namespace std;
void order(int* s1,int* s2)
{
     
     if(*s1 > *s2)
     {
            int temp;
            temp = *s1;
            *s1 = *s2;
            *s2 = temp;
     }
}
     
/////////////////////////////77777777

class myclass
{
      private:
              int* ptr;
              int len;
              public:
                     myclass(int n): len(n)
                     {
                       ptr = new int[len];
                     }
              void get_data()
              {
                   for(int i = 0; i < len; i++)
                   {
                   cout << "Enter data: ";
                   cin >> *(ptr+i) ; 
                   } 
              }
              
              void put_data()
              {
                   for(int i = 0; i < len; i++)
                    cout<<*(ptr+i)<<endl;
                    
              }
              
             int most_bignumber()
              {
                
                int big=0;
                 for(int i = 0; i < len-1; i++){
                   for(int k = i+1; i < len; k++){
                     order(ptr+i,ptr+k);
                                                    }
                                                    }
                      big=*ptr+len;                              
                  
                  return big;
              }  
              //deleting
             ~myclass()
             { 
                      delete[] ptr;  
                      cout << " bye bye " << endl;
             }
                    

};
                      
             
int main(int argc, char *argv[])
{  
     int big=0;
    myclass n1(4);
    n1.get_data();
    n1.put_data();

    big = n1.most_bignumber();
    cout << big << endl;
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

i want to sort data and i writing most big number.but i can't it.problem is order function or most_bignumber().but i don't see.it's working but I take runtime error.I maybe use (**) syntax but it's doesnt necessary.I'am sure. what do you think about this and help me please ?
Hint: Line 54 -- you are doing something differently there than you are on other lines like 34 and 41.
thank u.but line 34 or 41 working.also i delete most_bignumber() it's working.so there aren't problem.maybe line 54:S. my problem is order or most_bignumber() but i dont solve it
Yes, I agree. Your problem is on line 54. I suggested that you compare line 54 to lines 34 and 41. 34 and 41 work right; 54 doesn't. What are you doing differently?
Topic archived. No new replies allowed.