Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Closed Thread
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-11-2003, 05:56 PM   PM User | #1
Xantippe
New to the CF scene

 
Join Date: Aug 2003
Location: Indiana, USA
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Xantippe is an unknown quantity at this point
Java Array Help!

I have this for code, and i need to come up with something to use in the areas of:

insertName(String name)
and
deleteName(String name)

What i need is some code to insert names into a list of names and then code to delete names from that list. Any help would be appreciated.. Here is the code:

(There is also more code after this code that has to do with the names im using. The end of this code is depicted by this line of dashes below this code.)

All text within the dashed lines is the actual code.

-----------------------------------------------------------------------

public class LinkedList
{
private int mySize = 100;
private int myNextEntry = 0;
private int myEndPointer = 0;
public String myName[] = new String[100];
public int myLink[] = new int[100];
public int myHeadPointer = 0;

public void insertName(String name)
{
}

public void deleteName(String name)
{
}

public void printNames()
{
int currentLink = myHeadPointer;
while (currentLink != -1)
{
System.out.print(currentLink);
System.out.print(" "+myName[currentLink]+" ");
System.out.println(myLink[currentLink]);
currentLink = myLink[currentLink];
}
System.out.println();
}

public void sortNames()
{
int currentLink;
int lastLink;
int tempLink;

for (int i=1; i<myNextEntry; i++) {
currentLink = myHeadPointer;
lastLink = -1;
while (myLink[currentLink] != -1)
{
if (myName[currentLink].compareTo(myName[myLink[currentLink]])>0) {
if (lastLink == -1 )
{
lastLink = myLink[currentLink];
myHeadPointer = myLink[currentLink];
}
else
myLink[lastLink] = myLink[currentLink];
tempLink = myLink[myLink[currentLink]];
myLink[myLink[currentLink]] = currentLink;
myLink[currentLink] = tempLink;
}
else {
lastLink = currentLink;
currentLink = myLink[currentLink];
}
}
}
}

public void addName(String name)
{
myName[myNextEntry] = name;
myLink[myEndPointer] = myNextEntry;
myLink[myNextEntry] = -1;
myEndPointer = myNextEntry;
myNextEntry++;
}

}

-----------------------------------------------------------------------

(This is the other code I was talking about earlier. Any help with this would be great. Thanks.)

-----------------------------------------------------------------------

class DoLinkedList
{
public static void main(String args[])
{
LinkedList names = new LinkedList();

names.addName("Adam");
names.addName("Charlie");
names.addName("Bob");
names.addName("Doug");
names.addName("Fred");
names.addName("Edward");

names.printNames();
names.sortNames();
names.printNames();
names.insertName("Jack");
names.printNames();
names.insertName("George");
names.printNames();
names.insertName("Harold");
names.printNames();
names.insertName("Ivan");
names.printNames();
names.deleteName("Fred");
names.printNames();
names.deleteName("Jack");
names.printNames();
names.deleteName("Adam");
names.printNames();
names.deleteName("Ralph");
names.printNames();
}
}

-----------------------------------------------------------------------

Let me know if you need any other information.. I have the 2 class files that go along with this if you need em.
__________________
Xantippe
Digital Web Design
Xantippe is offline  
Old 11-11-2003, 07:08 PM   PM User | #2
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
This looks like a homework assignment. You need to do your homework yourself. If you need help ask specific questions and we can guide you in the right direction but we are not going to write the code for you.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline  
Old 11-14-2003, 05:28 AM   PM User | #3
Xantippe
New to the CF scene

 
Join Date: Aug 2003
Location: Indiana, USA
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Xantippe is an unknown quantity at this point
Ok well since you wont just give me the code.. Then i geuss what i want is to know exactly where i should start with what i need.. cause i dont know the first thing about java and i am not taking a class for java at this point, this is just something to skim all the different kinds of program languages. In my post i said what i needed, if you can tell me what to do to start with this, id be happy. (Id be happier if u just came up with the code yourself, but that aint gonna happen).
__________________
Xantippe
Digital Web Design
Xantippe is offline  
Old 11-14-2003, 05:45 AM   PM User | #4
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
Well if you are trying to learn Java then you should probably start with the basics before you jump right into working with linked lists and other advanced topics. Linked lists are a concept taught in most all programming courses and teachers typically assign problems very similar to this to their students which is why this looks much like a homework assignment.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline  
Old 11-15-2003, 01:47 AM   PM User | #5
Xantippe
New to the CF scene

 
Join Date: Aug 2003
Location: Indiana, USA
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Xantippe is an unknown quantity at this point
Well that is nice, but id still like some idea of which direction to go, cause this is due on monday and i am still without any idea of what to do...

And in your last post, you said something like "if im trying to learn java" well im not, i said that in one of my posts, at this point at least, im not trying to learn java, but my teacher insists on using it, and so i need to get this asignment done...

If you can help me out with what i should do that would be great WITHOUT me having to learn too much java... I know what a linked list looks like (teacher showed the class on a chalk board) but i just dont know how to script it...
__________________
Xantippe
Digital Web Design
Xantippe is offline  
Old 11-15-2003, 02:43 AM   PM User | #6
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
If your teacher required you to do this in java and you do not wish to learn java then you need to take that issue up with your teacher. And since you have no intention of learning java then there is no way you are going to complete this assignment and we are still not going to do your homework for you.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline  
Closed Thread

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:36 PM.


Advertisement
Log in to turn off these ads.