LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-02-2006, 06:34 PM   #1
thefalling
LQ Newbie
 
Registered: Sep 2006
Posts: 14

Rep: Reputation: 0
Sort test for an ArrayList (java)


Im writing a program for a programming class, and need to test to see if an ArrayList is sorted.

There is a function that sorts the arrayList, but I have another function that is supposed to print the ArrayList into a text file if the ArrayList is sorted.

Is there a class in the java API that contains a fuction to test if the ArrayList is sorted?
 
Old 12-02-2006, 09:42 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
i havent used java in a while but i Know theyre are interfaces that classes can implement ( Comparable or Comparator i think) to allow them to be sorted, ie being able to compare if obj1 is > obj2. if you are storing objects of classes that you have made then look into these interfaces to see how to design the required method for your case.

i dont think there is any generic 'sort' function because it depends completely on the data, and how it _can_ be sorted, what the first element would be, etc etc.

sorting methods arent overly complicated. in your add or insert method compare the new item to items that are already in the list. the ones that are in the list you know will already be sorted.

im kinda tired right now so dont know if im helping--hope it does help.
 
Old 12-02-2006, 09:42 PM   #3
dinojerm
Member
 
Registered: Apr 2004
Location: NJ,US
Distribution: Debian Sid
Posts: 33

Rep: Reputation: 15
If there isn't a function for that in the standard library, it would be trivial to write one (one way is to compare each adjacent item to see if they are in proper order)
 
Old 12-02-2006, 10:32 PM   #4
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 52
http://www.google.ca/search?hl=en&q=...e+Search&meta=
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java - problems with selection sort gomez6211 Programming 1 09-22-2006 11:54 PM
Is there a line limit with the sort utility? Trying to sort 130 million lines of text gruffy Linux - General 4 08-10-2006 08:40 PM
test type in java exodist Programming 8 02-18-2004 09:25 PM
ArrayList question (Java) ksgill Programming 5 10-14-2003 02:00 PM
Java ArrayList question ksgill Programming 2 10-12-2003 07:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration