www.webdeveloper.com
Results 1 to 7 of 7

Thread: check if array is Sorted or not??

  1. #1
    Join Date
    Apr 2012
    Posts
    3

    Post 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

  2. #2
    Join Date
    Nov 2010
    Posts
    24
    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.

  3. #3
    Join Date
    Apr 2012
    Posts
    3
    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.


  4. #4
    Join Date
    Apr 2012
    Location
    New Delhi
    Posts
    4
    I m confuse about your question Almutasim. Do you want to sort some number is array or something else.

  5. #5
    Join Date
    Apr 2012
    Posts
    3
    Quote Originally Posted by pawanmandav View Post
    I m confuse about your question Almutasim. Do you want to sort some number is array or something else.


    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 .

  6. #6
    Join Date
    May 2013
    Posts
    1
    i am facing same problem for some time and finding solution ,but now i got this solution, thank you.

  7. #7
    Join Date
    Mar 2013
    Location
    Iasi, Romania
    Posts
    53
    Still need that class?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles