Article View: borland.public.jbuilder.java.language
Article #649Re: list class
From: elrond_III
Date: Tue, 21 Dec 2004 17:04
Date: Tue, 21 Dec 2004 17:04
72 lines
4022 bytes
4022 bytes
Scott wrote:
> That piece of code definately seemed to do the job, however instead of a
> blank it return the word null. Is there a way to have the blank space listed
> instead? Sorry to be such a pest, but I'm sort of learning this on my own
> and am always looking for more info. Appreciate your help, and the others in
> this group.Once I have this done, I have other things that i'd like to play
> around with.
[snip]
Hm, I am not clearly understanding what you want (maybe because my
english is boor). What do you want do return?
your function signiture from remove (the name of a function, return
types and arguments) is:
public void remove(String s)
If you need your code there you don't return something?
[if you want do know: UML notation of your function is + (public) remove
(the name) (s:String (name and type of argument) ):void (return type),
in short: +remove(s:String):void {just if I write that once, so you
understand if you don't still know]
Lets discuss our function remove more detailed:
first you have to search for the string, to get the position. Then you
remove the word from the list, left shift all references, and set the
last word null. You might want to have the last word "".
If you set this your array is large enough to fit the next wort without
resizing. If you remove 3 times, you can add 3 times a word. Got the
idear? If you decrement your class member count everytime you remove,
and check if count's value is smaller than the size you can insert words
at the right place with add....
public void remove(String s) {
int location = locate(s);
for(int counter = rem_place; counter < (data.length - 1); counter++) {
data[counter] = data[count + 1];
}
data[counter + 1] = null; // this sets the *last* entry null
// or:
// data[counter + 1] = ""; (blank string)
count--; //we do this so we don' have to check a
}
public void add(String s) {
if(count <= array.length) {
data[count] = s;
count++;
} else {
data[count] = s;
count = count + 1;
String[] tempdirectory = new String[count * 2];
System.arraycopy(data, 0, tempdirectory, 0, count);
data = tempdirectory;
}
}
hope this helped ^^
--
--------------------------------------------------------------
Elrond_III -==: Hack the World :==-
g:R->R; [a,b] in D(g) and g[a,b] in [a,b] and for all x1,x2 in [a,b]
|g(x1)-g(x2)|<=L*|x1-x2| with L <= 1 then one s in [a,b] exist with
s=g(s)
-"Banachscher Fixpunktsatz"
Technical Details
Message-ID:
<41c857ef$0$26996$3b214f66@aconews.univie.ac.at>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!t-online.de!irazu.switch.ch!switch.ch!newsmi-eu.news.garr.it!NewsITBone-GARR!newscore.univie.ac.at!aconews-feed.univie.ac.at!aconews.univie.ac.at!not-for-mailReferences:
<0Nkwd.12381$Ae.6831@newsread1.dllstx09.us.to.verio.net> <41c82ae7$0$22342$3b214f66@aconews.univie.ac.at> <zDWxd.12514$Ae.10718@newsread1.dllstx09.us.to.verio.net> <41c847c2$0$26996$3b214f66@aconews.univie.ac.at> <IaYxd.12520$Ae.9292@newsread1.dllstx09.us.to.verio.net>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,62cee13431c73458 X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!t-online.de!irazu.switch.ch!switch.ch!newsmi-eu.news.garr.it!NewsITBone-GARR!newscore.univie.ac.at!aconews-feed.univie.ac.at!aconews.univie.ac.at!not-for-mail Date: Tue, 21 Dec 2004 18:04:02 +0100 From: elrond_III <elrond_III@gmx.at> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040608 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: list class References: <0Nkwd.12381$Ae.6831@newsread1.dllstx09.us.to.verio.net> <41c82ae7$0$22342$3b214f66@aconews.univie.ac.at> <zDWxd.12514$Ae.10718@newsread1.dllstx09.us.to.verio.net> <41c847c2$0$26996$3b214f66@aconews.univie.ac.at> <IaYxd.12520$Ae.9292@newsread1.dllstx09.us.to.verio.net> In-Reply-To: <IaYxd.12520$Ae.9292@newsread1.dllstx09.us.to.verio.net> X-Enigmail-Version: 0.84.1.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Lines: 72 Message-ID: <41c857ef$0$26996$3b214f66@aconews.univie.ac.at> NNTP-Posting-Host: a-183.dsl.tu-graz.ac.at X-Trace: 1103648751 aconews.univie.ac.at 26996 129.27.232.183 X-Complaints-To: abuse@univie.ac.at