| | |
SortedList & List Program
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2008
Posts: 11
Reputation:
Solved Threads: 0
Hello,
I'm trying complie this SortedList Program and List Java, but I'm alot errors. If someone can help with this, I really appricated.
Thanks
I'm trying complie this SortedList Program and List Java, but I'm alot errors. If someone can help with this, I really appricated.
Thanks
•
•
•
•
import java.util.Iterator;
/*
*
* SortedList.java
*
*/
public class SortedList<E extends Comparable<? super E>> extends List<E> {
private int size;
public SortedList(){
head = null;
size = 0;
}
public void insert(E data){
if(head == null){
head = new Node<E>(data);
size++;
} else {
Node<E> n = head;
while(n.next != null){
}
n.next = new Node<E>(data);
size++;
}
}
public void remove(E data) {
E.data = null;
if (head != null)
temp = head.data;
head = head.next;
return temp;
}
public E retrieve(int index){
if (index < size)
return size;
else
return null;
}
public boolean search(E data){
if(E.data < 1 || E.data > size())
return false;
Node<T> = head;
for(int i = 1; i < index; i++)
{
if(Node<T>.getNext() == null)
return false;
Node<T> = Node<T>.getNext();
}
Node<T>.setNext(Node<T>.getNext().getNext());
E.data--;
return true;
}
public Iterator<E> iterator() {
if (index < null || index > E.data)
throw new IndexofBoundException(Integers.toSTring(index));
return index;
else
return null;
}
}
•
•
•
•
/*
*
* List.java
*
*/
public abstract class List<E> implements Iterable<E> {
protected class Node<T> {
protected Node(T data) {
this.data = data;
}
protected T data;
protected Node<T> next;
}
public abstract void insert(E data);
public abstract void remove(E data);
public abstract E retrieve(int index);
//public abstract boolean search(E data);
protected Node<E> head;
}
Last edited by deven1974; Nov 21st, 2008 at 8:15 pm.
Hello, deven1974
Lets start:
1. Illegal use of data and datatypes:
It is equal, if you write this
2. You didn't declare variable temp, but use it.
3. Why are you setting your just entered parameter no null and the working with it?
Lets start:
1. Illegal use of data and datatypes:
java Syntax (Toggle Plain Text)
public void remove(E data) { E.data = null; if (head != null) temp = head.data; head = head.next; return temp; }
java Syntax (Toggle Plain Text)
String s; String.s = null;
3. Why are you setting your just entered parameter no null and the working with it?
Last edited by cscgal; Nov 21st, 2008 at 8:36 pm. Reason: Fixed code tag
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
•
•
Join Date: Nov 2008
Posts: 11
Reputation:
Solved Threads: 0
Hello,
Hey, thanks for you help, but I have little clue on this program. The is program I have do for my class. If you can able help with complie error message that I'm get while running this program.
Thanks
Should I
At the bottom is my program that I have do.
The Sorted List ADT
Implement the SortedList class. The SortedList class extends
the List class. Both can be seen here. Your assignment is to
implement all of the abstract methods of the List class. They are:
* insert
* iterator
* remove
* retrieve
* search
You must also implement an Iterator inner class for the
SortedList class. You must submit a modified SortedList.java
file with your source code. Do not submit and do not modify
the List.java file.
Hey, thanks for you help, but I have little clue on this program. The is program I have do for my class. If you can able help with complie error message that I'm get while running this program.
Thanks
Should I
String s; String.s = null;
At the bottom is my program that I have do.
The Sorted List ADT
Implement the SortedList class. The SortedList class extends
the List class. Both can be seen here. Your assignment is to
implement all of the abstract methods of the List class. They are:
* insert
* iterator
* remove
* retrieve
* search
You must also implement an Iterator inner class for the
SortedList class. You must submit a modified SortedList.java
file with your source code. Do not submit and do not modify
the List.java file.
As I can see, you didn't read this post "We only give homework help to those who show effort". All I can do is give you advices:
1. About String s: String - is a class, when you create an object of class, the class "do not know about it". So you can't cll the object from the class (String.s = null). Also as in your program.
2. The phrase "data=null" in the begginig of the method is wrong (consider, you use it later...).
3.Befor using variables? you have to declare. That way compiler understands, what you will store in it. In your case the type is "E". this mean, that it unknown now, but will be known later. Also you have to know is the base type for all refference types is Object.
4. If you are writing "public void remove(E data)" it means, that function doesn't return value. The return keyword is not out of place.
Also you can answer a questions and I'll try to answer. Good luck.
1. About String s: String - is a class, when you create an object of class, the class "do not know about it". So you can't cll the object from the class (String.s = null). Also as in your program.
2. The phrase "data=null" in the begginig of the method is wrong (consider, you use it later...).
3.Befor using variables? you have to declare. That way compiler understands, what you will store in it. In your case the type is "E". this mean, that it unknown now, but will be known later. Also you have to know is the base type for all refference types is Object.
4. If you are writing "public void remove(E data)" it means, that function doesn't return value. The return keyword is not out of place.
Also you can answer a questions and I'll try to answer. Good luck.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
![]() |
Other Threads in the Java Forum
- Previous Thread: Plot Chart from a Txt file
- Next Thread: Hash Table
| Thread Tools | Search this Thread |
actuate android api applet application array arrays automation balls binary bluetooth bold business c++ chat class classes client code codesnippet collections component coordinates database defaultmethod doctype dragging draw ebook eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui hql html ide image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list loop looping map method methods mobile mysql netbeans newbie nextline numbers oracle parameter php print problem program programming project recursion recursive scanner screen server set size sms sort sql string sun swing swt threads time tree user websites windows





