• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Java LinkedList

 
Greenhorn
Posts: 3
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Iwant to declare a variable of type ListNode in java, to use it for Insertion , but I got an error => ListNode cannot be resolved to a type
I was thinking thiere is a builting class called ListNode

public class Data {


private ListNode head; // ListNode cannot be resolved to a type
private ListNode current; // ListNode cannot be resolved to a type
private ListNode previous; // ListNode cannot be resolved to a type

}

Thanks in advance
Asadun
 
Ranch Hand
Posts: 270
15
Android Angular Framework Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Asadun,

Java has a LinkedList class, as described here. Linked List JavaDoc. However, it does not require any special kind of node to use it. In classes I'd taken in the past, the linked list had to be built up out of nodes, and you had to manage head/tail, etc. But Java's Collection classes (located in java.util) provide for all the "linked list" operations, while letting you ignore the details of how a linked list works.

I looked up "ListNode" and it seems to be (as I suspected) the kind of thing students are assigned to write for data structures courses.
 
Marshal
Posts: 76833
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

L Foster wrote:. . . Java has a LinkedList class, . . . it does not require any special kind of node to use it. . . .

It probably supplies its own node class as a private inner class.

You are right that students are expected to provide their own ListNode (or similar) classes. I think a private inner class would be a good way to do it.
You had a broken link which I have corrected. When you use the URL button, simply paste the whole URL with ctrl‑V; that will overwrite the http:// bit which is provided by the URL tags automatically.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sohaib Sabir wrote:I was thinking thiere is a builting class called ListNode


Nope.

So: do you want to use a LinkedList to add an item, or do you want to write your own? Because there's a BIG difference between the two, and the latter is a lot tougher than the first.

The only other thing I would suggest is that if you want to roll your own, then start out with a single-linked list unless you've been told to do otherwise, because it's a lot easier to write.

Also: your implementation seems to be mixing up aspects of a list Node (previous), the List itself (head), and a list Iterator (current), so I'd get those sorted out before you go much further.

HIH

Winston
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic