Guest_imported
New member
- Jan 1, 1970
- 0
Hi everybody, i have the following code:
///////////////////////////////////////////////////
class listItem {
Object data = null;listItem next = null;listItem prev = null;
public pbInfo getData () {
return data;
}
public listItem (Object obj) {
data = obj; next = null; prev = null;
}
}
class doublyLinkedList {
listItem front = null;
listItem rear = null;
int numItems = 0;
public int getNumItems() {
return (numItems);
}
public void addData (Object obj)
{
if (front == null) {
front = new listItem (obj);
rear = front;
// initialization
}
else {
listItem listPtr = new listItem (obj);
listPtr.prev = rear;
rear.next = listPtr;
rear = rear.next;
} numItems++;
}
public String toString ()
{
listItem listPtr = front;
String s = "List: (" + numItems + " items)";
int i = 1;
while (listPtr != null) {
s += "\nItem# " + i + ": " + listPtr.getData();
i++;
listPtr = listPtr.next;
}
return s + "\n";
}
public listItem getItemAtPosition (int i)
{
listItem listPtr = front;
for (int n=1; n<i; n++) {
listPtr = listPtr.next;
} return listPtr;
}
}
///////////////////////////////////////////////////
// Then I have a class object called info
class info {
public info () {
}
}
///////////////////////////////////////////////////
public void main (String[] argv) {
doublyLinkedList linkList = new doublyLinkedList ();
for (int n=0;n<10;n++) {
info newInfo = new info();
callList.addData(newInfo); // creates a link list of info
}
info tempInfo = new info();
tempInfo = linkList.getItemAtPosition.getData(); // *** ERROR HERE
/ / linkList.getItemAtPosition.getData(); returns an Object which
is not compatible with info
}
///////////////////////////////////////////////////
/* linkList creates a link list of listItem object (which contains an
info object) by calling doublyLinkedList.addData */
/* then a temporary info object is created */
/* so that the info object can be pulled out from listItem */
/* linkList.getItemAtPosition returns a listItem */
/* then listItem.getData returns data, which is of type Object which
here would be an info Object */
/* but then i get that error */
/* any help would very much appreciated */
/* Thank you */
///////////////////////////////////////////////////
///////////////////////////////////////////////////
class listItem {
Object data = null;listItem next = null;listItem prev = null;
public pbInfo getData () {
return data;
}
public listItem (Object obj) {
data = obj; next = null; prev = null;
}
}
class doublyLinkedList {
listItem front = null;
listItem rear = null;
int numItems = 0;
public int getNumItems() {
return (numItems);
}
public void addData (Object obj)
{
if (front == null) {
front = new listItem (obj);
rear = front;
// initialization
}
else {
listItem listPtr = new listItem (obj);
listPtr.prev = rear;
rear.next = listPtr;
rear = rear.next;
} numItems++;
}
public String toString ()
{
listItem listPtr = front;
String s = "List: (" + numItems + " items)";
int i = 1;
while (listPtr != null) {
s += "\nItem# " + i + ": " + listPtr.getData();
i++;
listPtr = listPtr.next;
}
return s + "\n";
}
public listItem getItemAtPosition (int i)
{
listItem listPtr = front;
for (int n=1; n<i; n++) {
listPtr = listPtr.next;
} return listPtr;
}
}
///////////////////////////////////////////////////
// Then I have a class object called info
class info {
public info () {
}
}
///////////////////////////////////////////////////
public void main (String[] argv) {
doublyLinkedList linkList = new doublyLinkedList ();
for (int n=0;n<10;n++) {
info newInfo = new info();
callList.addData(newInfo); // creates a link list of info
}
info tempInfo = new info();
tempInfo = linkList.getItemAtPosition.getData(); // *** ERROR HERE
/ / linkList.getItemAtPosition.getData(); returns an Object which
is not compatible with info
}
///////////////////////////////////////////////////
/* linkList creates a link list of listItem object (which contains an
info object) by calling doublyLinkedList.addData */
/* then a temporary info object is created */
/* so that the info object can be pulled out from listItem */
/* linkList.getItemAtPosition returns a listItem */
/* then listItem.getData returns data, which is of type Object which
here would be an info Object */
/* but then i get that error */
/* any help would very much appreciated */
/* Thank you */
///////////////////////////////////////////////////