Computer Science Canada
Programming C, C++, Java, PHP, Ruby, Turing, VB
Username:
Password:
Register
Wiki
Blog
Search
Turing
Chat Room
Members
Please Help, should be working but isn't
Index
->
Programming, Java
->
Java Help
Author
Message
EricUnreal
Posted:
Thu Jan 26, 2012 11:19 pm
Post subject: Please Help, should be working but isn't
My final is tommorrow and i'm having trouble with some questions that are similar to those that will be on the exam. Here's what i have:
I have to insert a word into the list while maintaining alphabetical order. What i'm trying to do is insert the word, then just re-sort the list.
import java.util.*;
import java.io.*;
public class WordList
{
private ArrayList<String> list;
public WordList()
{
list = new ArrayList<String>();
getData();
}
public void addWord(String aWord)
{
list.add(aWord);
for (int current=0; current<list.length; current++) {
int lowPos = current;
for(int i=current; i<list.length; i++) {
if( list[i].compareTo(list[lowPos])<0 ) {
lowPos = i;
}
}
String temp = list[current];
list[current] = list[lowPos];
list[lowPos] = temp;
}
}
}
Sponsor
Sponsor
EricUnreal
Posted:
Thu Jan 26, 2012 11:25 pm
Post subject: RE:Please Help, should be working but isn\'t
To clarify, it's giving me an error at list.length; which i dont think it should because it is an ArrayList
Tony
Posted:
Thu Jan 26, 2012 11:49 pm
Post subject: RE:Please Help, should be working but isn\'t
there is no such field in ArrayList
Tony's
programming blog
. DWITE - a
programming contest
.
EricUnreal
Posted:
Thu Jan 26, 2012 11:52 pm
Post subject: Re: RE:Please Help, should be working but isn\'t
Tony @ Thu Jan 26, 2012 10:49 pm wrote:
there is no such field in ArrayList
Well what could I use instead? or even in an Array.
Tony
Posted:
Fri Jan 27, 2012 12:23 am
Post subject: RE:Please Help, should be working but isn\'t
Perhaps you'll find one of the available methods to be suitable?
http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html
Tony's
programming blog
. DWITE - a
programming contest
.
Display posts from previous:
All Posts
1 Day
7 Days
2 Weeks
1 Month
3 Months
6 Months
1 Year
Oldest First
Newest First
Index
->
Programming, Java
->
Java Help
Page
1
of
1
[ 5 Posts ]
Jump to:
Select a forum
CompSci.ca
------------
- Network News
- General Discussion
General Forums
-----------------
- Hello World
- Featured Poll
- Contests
Contest Forums
-----------------
- DWITE
- [FP] Contest 2006/2008
- [FP] 2005/2006 Archive
- [FP] 2004/2005 Archive
- Off Topic
Lounges
---------
- User Lounge
- VIP Lounge
Programming
--------------
- General Programming
General Programming Forums
--------------------------------
- Functional Programming
- Logical Programming
- C
C
--
- C Help
- C Tutorials
- C Submissions
- C++
C++
----
- C++ Help
- C++ Tutorials
- C++ Submissions
- Java
Java
-----
- Java Help
- Java Tutorials
- Java Submissions
- Ruby
Ruby
-----
- Ruby Help
- Ruby Tutorials
- Ruby Submissions
- Turing
Turing
--------
- Turing Help
- Turing Tutorials
- Turing Submissions
- PHP
PHP
----
- PHP Help
- PHP Tutorials
- PHP Submissions
- Python
Python
--------
- Python Help
- Python Tutorials
- Python Submissions
- Visual Basic and Other Basics
VB
---
- Visual Basic Help
- Visual Basic Tutorials
- Visual Basic Submissions
Education
-----------
- Student Life
Graphics and Design
-----------------------
- Web Design
Web Design Forums
---------------------
- (X)HTML Help
- (X)HTML Tutorials
- Flash MX Help
- Flash MX Tutorials
- Graphics
Graphics Forums
------------------
- Photoshop Tutorials
- The Showroom
- 2D Graphics
- 3D Graphics
Teams
------
- dTeam Public
Style:
Appalachia
blueSilver
eMJay
subAppalachia
subBlue
subCanvas
subEmjay
subGrey
subSilver
subVereor
Search:
You can syndicate this boards posts using the file
backend.php
or view the
topic map using sitemap.php.
Terms of Use
|
Privacy Policy