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 06-28-2004, 07:29 PM   #16
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30

so... to circumvent this problem you use arrays where you can just add to your array pointer a fixed amount of memory * the number of elements to skip, and that gives you your get()... is that more or less correct?
 
Old 06-28-2004, 07:53 PM   #17
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
that will help in (some|most) cases, but indexing will still be slower than in a real array and insertions/deletions into the middle of the list will not be great. Plus, get() would get slower and slower as the array grew since it would have to iterate over all the previous skip amounts. It could be the way ArrayList is done, I'm not sure.

The point I wanted to make is that since the OP is *only* iterating through the array, and not really indexing it except as a method of iteration, plus he wants to append to it an undefined number of times, a plain old linked list is the right structure.
 
Old 06-28-2004, 07:59 PM   #18
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
right... yes I didn't mean to extend the tangent, but you know... I got interested in it...

anyway as it has been stated before, the right way to write this program would be something like this with error handling:

Code:
int max = 0;
boolean reading = true;
while(reading) {
  int n = Integer.parseInt(JOptionPane.showInputDialog("Number:"));
  if(n > max) max = n;
  if(n == 0) reading = false;
}

JOptionPane.showMessageDialog("Max was " + max);
Thanks for the introspective aluser, very interesting.

B.
 
  


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
Problem displaying Bash array values. shinobi59 Programming 3 01-17-2006 05:45 PM
An idea for a survey: What country have the largest number of people prefer linux TruongAn LQ Suggestions & Feedback 2 09-11-2005 10:56 AM
number of element in a array of pointer? os2 Programming 7 03-09-2005 11:50 AM
repeated number in a 4x4 array xbaez Programming 3 11-21-2004 11:03 PM
Largest Known prime number is discovered by MSU Grad! bolinux General 3 12-03-2003 07:33 PM

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

All times are GMT -5. The time now is 09:01 AM.

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