Thread: single linked list - java
-
October 11th, 2007, 03:34 PM #1Junior 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;
}
-
October 11th, 2007, 04:32 PM #2
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
-
Linked Lists C++
By BattleToad in forum Webmastering and ProgrammingReplies: 2Last Post: July 17th, 2007, 08:54 AM -
Launching Java webpages with different Java settings?
By LostBok in forum Webmastering and ProgrammingReplies: 1Last Post: December 11th, 2006, 03:38 AM -
Several Modems Linked????
By megamiami1 in forum Networking and InternetReplies: 2Last Post: November 26th, 2004, 02:44 PM -
For those that still think Iraq was linked to 9/11
By MTAtech in forum IMO CommunityReplies: 100Last Post: September 17th, 2004, 12:52 PM -
Creating a Circular Linked List
By highrock in forum Webmastering and ProgrammingReplies: 1Last Post: March 28th, 2003, 08:20 PM



LinkBack URL
About LinkBacks



Reply With Quote



Via Wikipedia: Paranormal Witness is an American paranormal documentary television series described as featuring "eyewitness accounts" from "everyday people" who claim to have experienced paranormal...
Paranormal Witness is an American...