V
V
Vadim kyklaed2018-03-14 17:25:02
C++ / C#
Vadim kyklaed, 2018-03-14 17:25:02

I don't understand where is the type incompatibility?

Hello, tell me what I'm doing wrong
[Error] invalid conversion from 'int' to 'int*' [-fpermissive]

template<typename T3,typename T4>
void Bubble(T3 N, T4 *mass[]){
  
  bool swap;
  do {
  swap=false;
  for (int i=0;i<N-1;i++){
      if (mass[i]<mass[i+1]){
          swap=true;
          cout<<mass[i];
          T3 temp = mass[i];
          mass[i]=mass[i+1];
          mass[i+1]=temp;
        }
    }
  } while (swap);
  
  for ( int i =N-1;i>=0;i--){
    cout<<mass[i]<<"\n";
  }
}


int main(){
  int n;
  int m;
  cin>>n;
  int *mass = new int [n];
  for(int i=0;i<n;i++){
    cin>>m;
    mass[i]=m;
  }
  Bubble(n, &mass);
  return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
Xano, 2018-03-14
@Xano

in the Bubble function, the variable mass is of type **int, which is why all the problems.
mass[i+1]=temp: mass[i+1] is of type *int, temp is of type
int

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question