Linked List

Linked List implementation in a class

Page 1 of 1

3 Replies - 8600 Views - Last Post: 07 September 2005 - 02:43 AM Rate Topic: -----

#1 Pavs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-August 05

Linked List

Posted 23 August 2005 - 06:28 PM

This is what I have:

public class prob_1{

public static void main(String[] args){

prob_1.ListNode L = new prob_1.ListNode(args[0]); ----error

for(int loop=0; loop < args.length; loop++){
L.setNext(new prob_1.ListNode(args[loop])); ------error
}//End loop
}//End main

public class Listnode {
//*** fields ***
private Object data;
private Listnode next;

//*** methods ***
// 2 constructors
public Listnode(Object d) {
this(d, null);
}

public Listnode(Object d, Listnode n) {
data = d;
next = n;
}

// access to fields
public Object getData() {
return data;
}

public Listnode getNext() {
return next;
}

// modify fields
public void setData(Object ob) {
data = ob;
}

public void setNext(Listnode n) {
next = n;
}
}

I have to have a linked list class and my main program in one java file. The two places where im getting errors are pointed out above.

I'm probably doing something stupid so I would appreciate it if someone told me what it is.
thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Linked List

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Linked List

Posted 23 August 2005 - 06:55 PM

Can you post the errors?
Was This Post Helpful? 0
  • +
  • -

#3 Pavs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-August 05

Re: Linked List

Posted 24 August 2005 - 07:59 AM

prob_1.java:8: cannot resolve symbol
symbol: class ListNode
location: class prob_1
>> prob_1.<<ListNode L = new prob_1.ListNode(args[0]);

prob_1.java:8: cannot resolve symbol
symbol: class ListNode
location: classs prob_1
prob_1.ListNode L = new >>prob_1.<<ListNode(args[0]);

prob_1. java:12: cannot resolve symbol
symbol: class ListNode
location: class prob_1
L.setNext(new >>prob_1.<<ListNode(args[loop]));

Im not sure how to put the linked list class in my prob_1 main program class and then how to use the linked list.
Was This Post Helpful? 0
  • +
  • -

#4 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Linked List

Posted 07 September 2005 - 02:43 AM

I've just spotted a typo in your code:

You declared as:
public class Listnode ...

But you reference it as:
prob_1.ListNode ...

Java is case sensitive. Also I think you can simply write Listnode in prob_1 as it is within its scope. So I assume you can simply write:
Listnode L = new .Listnode(args[0]);

I hope it helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1