-
How to implement pointer concept in java
How to write a program for a linkedlist without using the collection framework
-
All datatypes (other than the simple/base/elemental types int, short, float, char, boolean, etc.) are "reference" types. When you use the instance's name, you are passing a reference to the memory location where the object is being stored. So, when you build your linked list, you will not be copying objects, but storing references to the next Node and the element being stored in the Node of interest. The location's name acts, almost, like a pointer.
So ... what's holding you up? Just write a Node class which has the links you want (prior, next, parent, child, whatever) as some of the fields and the methods you need to manipulate your element.
-
Can u please send me the program regarding this. I need it.. i tried to write one but failed..
Thank U
-
why don't you post your code for the part where your attempt failed and we can work on it?
-
I have written a sample. It should be good enough for you to get started. You should try to implement delete and iterator yourself.
public class Node <T>{
private T item;
private Node<T> next;
public Node (T item)
{
this.item = item;
}
public void set(T item)
{
this.item = item;
}
public T get()
{
return item;
}
public void setNext(Node<T> node)
{
next = node;
}
}
public class LinkedList <T>{
private Node<T> last;
private Node<T> first;
private int count;
public LinkedList()
{
first = null;
last = null;
count = 0;
}
public LinkedList(T item)
{
first = new Node<T>(item);
last = first;
count++;
}
public void add(T item)
{
if(count == 0)
{
first = new Node<T>(item);
last = first;
}
else
{
Node<T> tmpNode = new Node<T>(item);
last.setNext(tmpNode);
last = tmpNode;
}
count++;
}
public int size()
{
return count;
}
}
public class main {
/**
* @param args
*/
static public void main(String[] args) {
int MAX = 10;
LinkedList<Integer> list = new LinkedList<Integer>();
for(int i = 0; i< MAX; i++)
{
list.add(i);
}
}
}
Similar Threads
-
Replies: 1
Last Post: 05-13-2005, 06:46 AM
-
Replies: 0
Last Post: 02-18-2002, 05:39 PM
-
By Phil Weber in forum Architecture and Design
Replies: 0
Last Post: 04-19-2001, 06:36 PM
-
Replies: 0
Last Post: 01-15-2001, 01:18 AM
-
By JJ in forum Enterprise
Replies: 1
Last Post: 07-06-2000, 04:50 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks