fork download
  1. //sorting by not moving the data but only ponter position
  2. #include<conio.h>
  3. #include<stdio.h>
  4. #include<iostream.h>
  5. #include<malloc.h>
  6. #define MAX 7
  7. static int *ptr[MAX];
  8. void sort(int A[]);
  9. void display();
  10. int main()
  11. {
  12. int A[] = {11,89,65,2,5,9,1};
  13.  
  14.  
  15. int i;
  16. for(i=0;i<MAX;i++)
  17. ptr[i] = &(A[i]);
  18.  
  19. sort(A);
  20. cout<<"\n"<<*ptr[0]<<" "<<*ptr[1];
  21. cout<<"\n AFTER SORTING - \n";
  22. display();
  23. getch();
  24. return 0;
  25. }
  26. void sort(int A[])
  27. {
  28. int i ;
  29. //int **a = &ptr[0];
  30. for(i=0;i<MAX-1;i++)
  31. {
  32. cout<<"\n case number = "<<i;
  33. for(int j = 0;j<MAX-i;j++)
  34. {
  35. if((*(ptr[j]))> (*(ptr[j+1]))) //this means A[j] > A[j+1]
  36. {
  37. int *a = ptr[j+1];
  38. ptr[j+1] = ptr[j];
  39. ptr[j] = a;
  40. display();
  41.  
  42. }
  43. }
  44. }//end of outer loop
  45. }//end of function
  46. void display()
  47. {
  48. int i;
  49. cout<<"\n";
  50. for(i=0;i<MAX;i++)
  51. cout<<" "<<*ptr[i];
  52. //for(i=0;i<MAX;i++)
  53. //cout<<" "<<ptr[i];
  54.  
  55. }
  56.  
  57.  
  58.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:18: error: conio.h: No such file or directory
prog.cpp:4:21: error: iostream.h: No such file or directory
prog.cpp: In function ‘int main()’:
prog.cpp:20: error: ‘cout’ was not declared in this scope
prog.cpp:23: error: ‘getch’ was not declared in this scope
prog.cpp: In function ‘void sort(int*)’:
prog.cpp:32: error: ‘cout’ was not declared in this scope
prog.cpp: In function ‘void display()’:
prog.cpp:49: error: ‘cout’ was not declared in this scope
stdout
Standard output is empty