Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-06-2007, 12:10 AM
Member
 
Join Date: Jul 2007
Posts: 40
trill is on a distinguished road
Help with insertName(String name) and deleteName(String name)
Hi, I have this for code, and i need to come up with something to use in the areas of:

Code:
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:
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.

Code:
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.
Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 08:29 AM
zoe zoe is offline
Member
 
Join Date: Jul 2007
Posts: 40
zoe is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
String one198 New To Java 1 01-07-2008 10:59 AM
String vs new String bugger New To Java 20 11-26-2007 01:21 PM
Using java.util.Scanner to search for a String in a String Java Tip Java Tips 0 11-20-2007 05:59 PM
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String) baltimore New To Java 1 08-06-2007 08:45 AM
I can't seem to pass the value of a string variable into a string array mathias Java Applets 1 08-03-2007 11:52 AM


All times are GMT +3. The time now is 09:17 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org