+ 1

help me to fix this c++ insertion sort code

i took this code from insertion sort in c++ from a guide in this site but when i run it in my visual studio 2017 it shows me two error. 1-'void swap(int *,int *)': cannot convert argument 1 from 'int' to 'int *' 2-'cout': undeclared identifier. the code works in online compiler this is the code : #include <iostream> #include "stdafx.h" using namespace std; void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } void insertionSort(int arr[], int n) { int i, j; for (i = 1; i < n; i++) { j = i; while (j > 0 && arr[j - 1] > arr[j]) { swap(arr[j], arr[j - 1]); j--; } } } void printArray(int arr[], int size) { for (int i = 0; i < size; i++) cout << arr[i] << " "; } int main() { int arr[] = { 5, 2, 42, 6, 1, 3, 2 }; int n = sizeof(arr) / sizeof(arr[0]); insertionSort(arr, n); printArray(arr, n); return 0; }

28th Apr 2018, 7:54 PM
MeDoXs
MeDoXs - avatar
1 Antwort
0
Thank you.
28th Apr 2018, 9:09 PM
MeDoXs
MeDoXs - avatar