+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Sep 2007
    Posts
    4

    single linked list - java

     
    i am trying to write a program that implemets an interface using single linked list. i then am writing a tester program for the implementations. i am not sure if what i have done so far is correct, and some i have nothing for yet besides simple return statements. the ones that have just simple return statements are the ones i am unsure about, and the ones i have done, if they are not correct, please let me know. any help is appreciated.

    import java.util.*;
    import java.util.text;
    public interface List {
    //Appends the specified element to the end of this list and returns the specific position at which it was added.
    public int add(Object o){
    if (head == null){
    head = new Node (o, null);
    count++;
    }
    else

    Node current = head;
    while (current.link != null){
    current = current.link;
    }
    current.link = new Node (o, null);
    count++;
    }

    //Inserts the specified element at the specified position in this list.
    public void add(int index, Object o){
    if (head == null){
    head = new Node (o, null);
    count++;
    }
    else

    Node current = head;
    while (current.link != null){
    current = current.link;
    }
    current.link = new Node (o, null);
    count++;
    }

    }

    //Removes all of the elements from this list.
    public void clear(){
    }



    //Returns true if this list contains the specified element.
    public boolean contains(Object element){
    return false;
    }

    //Compares the specified object with this list for equality.
    public boolean equals(Object element){
    return false;
    }

    //Returns the element at the specified position in this list.
    public Object get(int index){
    return info;
    }

    //Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
    public int indexOf(Object element){
    }


    //Returns true if this list contains no elements.
    public boolean isEmpty(){
    if (head == null)
    return false;
    }

    //Removes the element at the specified position in this list.
    public Object remove(int index){
    if (move == n) {
    move = n.getNext();
    }
    else {
    Node tmp = move;
    while (tmp.getNext() != n) tmp = tmp.getNext();
    tmp.setNext( n.getNext() );
    }



    //Replaces the element at the specified position in this list with the specified element.
    public Object set(int index, Object o){
    return null;
    }

    //Returns the number of elements in this list.
    public int size(){
    return -1;
    }

    //Returns an array containing all of the elements in this list in proper sequence
    public Object[] toArray(){
    return null;
    }

    // Returns a String representation of the list.
    public String toString()
    {
    String result = "";
    NumListNode current = NumListNode;
    while (current != null)
    {
    result += current.numbers + "\n";
    current = current.next;
    }
    return result;

    }

  2. #2
    Real gangstas sip on Yacc jkrohn's Avatar
    Join Date
    Oct 2001
    Location
    Suckas-ville
    Posts
    4,554
    Use the CODE tag and indent that code.
    Signatures blow hard
    If your signature contains an ad of any kind, congratulations, you're on my ignore list.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Linked Lists C++
    By BattleToad in forum Webmastering and Programming
    Replies: 2
    Last Post: July 17th, 2007, 08:54 AM
  2. Launching Java webpages with different Java settings?
    By LostBok in forum Webmastering and Programming
    Replies: 1
    Last Post: December 11th, 2006, 03:38 AM
  3. Several Modems Linked????
    By megamiami1 in forum Networking and Internet
    Replies: 2
    Last Post: November 26th, 2004, 02:44 PM
  4. For those that still think Iraq was linked to 9/11
    By MTAtech in forum IMO Community
    Replies: 100
    Last Post: September 17th, 2004, 12:52 PM
  5. Creating a Circular Linked List
    By highrock in forum Webmastering and Programming
    Replies: 1
    Last Post: March 28th, 2003, 08:20 PM

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews