#include <iostream>
using namespace std;
class Bucket{
public:
Bucket();
void setN(int n);
void setArrayb();
void storeArray(int s, int cc, int **A);
int showdata(int cc);
private:
int n_elements;
int *b;
};
Bucket :: Bucket(){
;
}
void Bucket :: setN(int n)
{
n_elements = n;
}
void Bucket :: setArrayb(){
int *b = new int [n_elements + 1];
}
void Bucket :: storeArray(int s, int cc, int **A){
cout << this -> n_elements;
if(cc <= n_elements){
this -> b[cc] = A[0][s];
}
}
int Bucket :: showdata(int cc){
return this -> b[cc];
}
int main(){
int n = 10;
int** A = new int*[1];
for (int i = 0 ; i < 1 ; i++){
A[i] = new int [n + 1];
}
Bucket B[n + 1];
A[0][3] = 6;
int fb = 10;
B[1].setN(fb) ;
B[1].setArrayb();
B[1].storeArray(3, 1, A);
cout << B[1].showdata(1);
}
I'm trying to complete bucketsort with n bucket for A. n_element is the numbers of each bucket, after compiling, it's legal. But when I execute it, it cause segmentation fault.Can someone explain what happened in this code?
Using in linux environment by cygwin.