Sorting with pointer (solved)
Hi Every body ! Is someone can help me ? i'm just beginning with pointers. i'm trying using pointer to sort an array of numbers. i wrote a code with 2 loops. First loop, find the biggest number, the second put the number from the biggest to the shortest. the output give me 89 89 89 89 89 89... I don't understand why my pointers doesn't erase the biggest value before each loop ... thank you very much #include <iostream> using namespace std; int number[10]={10,43,56,83,43,89,56,89,76,7}; int big=number[0]; int *p; int sorting[10]={}; int main() { p = &number[0]; for (int i=0;i<10;i++) { for (int x=0;x<10;x++) { if (big>=number[x]) {big=big;} else {big=number[x]; p=&number[x]; } } *p=0; sorting[i] = big; cout << sorting[i] << " "; } return 0; }