void main()
{
int i,j,temp1,temp2;
int arr[8]={5,3,0,2,12,1,33,2};
int *ptr;
for(i=0;i<7;i++)
{ for(j=0;j<7-i;j++) {
if(*(arr+j)>*(arr+j+1))
{ ptr=arr+j;
temp1=*ptr++;
temp2=*ptr;
*ptr--=temp1;
*ptr=temp2;
clrscr();
for(i=0;i<8;i++)
printf(" %d",arr[i]);
getch(); }
This type of sorting can b performd by simply transferring all the matrix elements in a single dimension array of 1X16 size and then sorting this array and then transferring the elements back to 4X4 matrix. You can also treat the 4x4 matrix as a simple array using pointers and, thus, not need to transfer from matrix to array and back. Example, using ellipses (...) to simulate indentation for clarity... int matrix[4][4] = {...some values...} int *element; int flag = 1; while (flag == 1) { /* simple bubble sort */ ... flag = 0; ... /* loop from first element to next to last element */ ... for (element = &matrix[0][0]; element < &matrix[3][3]; element ++) { ... ... if (*element > *(element + 1)) { ... ... ... flag = 1; ... ... ... *element ^= *(element + 1); /* exclusive or swap */ ... ... ... *(element + 1) ^= *element; ... ... ... *element ^= *(element + 1); ... ... } ... } }
Knowledge and experience.
You cannot delete from an array.
which element of the array does this expression reference num[5]
Object[] arrayToBeSorted; Arrays.sort(arrayToBeSorted);
Sorting an array.
This type of sorting can b performd by simply transferring all the matrix elements in a single dimension array of 1X16 size and then sorting this array and then transferring the elements back to 4X4 matrix. You can also treat the 4x4 matrix as a simple array using pointers and, thus, not need to transfer from matrix to array and back. Example, using ellipses (...) to simulate indentation for clarity... int matrix[4][4] = {...some values...} int *element; int flag = 1; while (flag == 1) { /* simple bubble sort */ ... flag = 0; ... /* loop from first element to next to last element */ ... for (element = &matrix[0][0]; element < &matrix[3][3]; element ++) { ... ... if (*element > *(element + 1)) { ... ... ... flag = 1; ... ... ... *element ^= *(element + 1); /* exclusive or swap */ ... ... ... *(element + 1) ^= *element; ... ... ... *element ^= *(element + 1); ... ... } ... } }
// the build in sorting functions in Java will sort pretty much any array // of Comparable objects or primitives Arrays.sort(someArray);
Knowledge and experience.
here you will a good example on java sorting algorithm application http://javacodespot.blogspot.com/2010/08/java-sorting-animations.html http://javacodespot.blogspot.com/
Internal sorting it means we are arranging the number within the array only which is in computer primary memory. External sorting it is the sorting of numbers from the external file by reading it from secondary memory.
You cannot delete from an array.
by using index position we can find the particular element in array.
which element of the array does this expression reference num[5]
Object[] arrayToBeSorted; Arrays.sort(arrayToBeSorted);
in selection sorting at first we take first element of the list and start comparing with all the successive element of that list
(array.length - 1) will find the index of the last element in an array (or -1 if the array is empty).