私はC++で挿入ソートを試みていますが、私の./a.outはこれを返します:* `./insertion 'のエラー:ダブルフリーまたは破損(out):0x000000000154fc20 *ダブルフリーまたは破損(アウト):C++の0x000000000154fc20
なぜこのようなことが起こっているのか分かりません。私はこのような他の問題を抱えています。それはいつもコードについてです。私のコードで購入してください。
これはコードです:あなたのコードのスニペットで
#include<iostream>
#include<vector>
using namespace std;
void insertion(vector<int> v){
int tam = v.size();
int key,j,i;
for(i=1; i<tam; i++){
key = v[i];
j=i-1;
while(j>=0 && v[j]>key){
v[j+1] = v[j];
j--;
}
v[j]=key;
}
}
void print(vector<int> v){
cout<<endl;
for(int i = 0; i<v.size(); i++){
cout<<i+1<<".\t"<<v[i]<<"\n";
}
}
int main(){
cout<<"----------------INSERTION SORT----------------\n\n";
cout<<"\nPlease, fill the vector: \n\n";
vector<int> v;
int a;
bool response = true;
while(response){
cout<<"\nEnter your number: ";
cin>>a;
v.push_back(a);
cout<<"Another?(1/0): ";
cin>>response;
cout<<endl;
}
insertion(v);
print(v);
return 0;
}
を "と、それは、コードについては、常にだ" - はい、そうです。 –
デバッガを使用することを学ぶ –
Valgrindはここで助けになるでしょう。 -gでコンパイルしてください。 valgrind ./executable – PYA