Hello all ^_^
I want to sort an (one dimension array) using the following way only.
The way is :
We have this array :
Index : 0-----1-----2-----3-----4-----5-----6
Values: 10----5-----6-----11----2-----5-----1
2- Create a new array :
int []Sorting =new int [7]
3- now we want to find min number from the source array the put it in index 0 in the new array "Sorting" then make the min number in source array = 0 , like that :
this is the source array after one loop :
Index : 0-----1-----2-----3-----4-----5-----6
Values: 10----5-----6-----11----2-----5-----0
this is the sorted array :
Index : 0-----1-----2-----3-----4-----5-----6
Values: 1----null---null--null--null--null--null
4- We must loop this step to make "Sorting"array sorted, like this :
Index : 0-----1-----2-----3-----4-----5-----6
Values: 1-----2-----5-----5----6-----10-----11
======================================================================================
this is my source code :
public static void main(String[] args)
{
int [] RandomArray = new int [8];
for(int i=0;i<RandomArray.length;i++)
{
String element= JOptionPane.showInputDialog("Please insert any number "+ (i+1));
RandomArray [i]=Integer.parseInt(element);
}
int []SortedArray=new int [8];
for(int s=0; s< RandomArray.length;s++)
{
for(int d=0;d<RandomArray.length;d++)
{
if (s==d || RandomArray[s]==0)
{
}
else
{
int x ;
if (RandomArray[s]<RandomArray[d])
{
SortedArray[s] = RandomArray[s];
x=s;
}else
{
SortedArray[s] = RandomArray[d];
x=d;
}
RandomArray[x]=0;
}
}
}
}
please help me quickly.