check if array is Sorted or not??
a) Implement a function that examines an array and returns 0 or 1, where 0 indicates the array is unsorted and 1 indicates the array is sorted.
b) If array is unsorted, Implement a selection sort that removes duplicates during the sorting process.
please who has the function please post here the method
Could you just loop through the elements in the array and run a comparison of each against the previous element which returns false if one is out of order?
If they are strings use the compare function and if not then look into the Comparator http://www.tutorialspoint.com/java/j...comparator.htm
There are many selection sort examples available online [http://www.roseindia.net/java/beginn...ionSort.shtml] and you could use a Set temporarily to ensure no duplicates exist.
Your function has multiple elements so just break the problem apart.
Thank you Mr MaxAvion but actually, I am beginner in Java and I don't have a lot of experience
I will try to post what I do and Then correct to me the error.
I m confuse about your question Almutasim. Do you want to sort some number is array or something else.
Originally Posted by pawanmandav
Hello my friend I am sorry, maybe my question is not clear but I will try to explain it step by step
I want to write a java code to check whether the array(any array ) is sorted or not
if sorted return 1 and if the array is unsorted return 0
return means like (System.out.println)
That was about the first part that say ( a) Implement a function that examines an array and returns 0 or 1, where 0 indicates the array is unsorted and 1 indicates the array is sorted. )
Try just to solve the first part .
i am facing same problem for some time and finding solution ,but now i got this solution, thank you.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)