0

plz help me in writing the logic with out using the util packege classes in java? plz give the code for this program in linkedlists way (not by using util package classees)

import java.util.*;
public class arr1
{
public static void main(string args[])
{
list l1=new ArrayList(); // or list l1=new linkedlist();
l1.add("1");
l1.add("2");
l1.add("3");
Iterate i1=l1.iterate();
while(i1.hasNext())
{
 
system.out.println(i1.next());
 
}
}
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by ~s.o.s~
0

A linked list is nothing by collection of nodes which contain data and a pointer to the next node.

Node
-----^------
[data | ref] -> [data | ref] -> ....

Create a class called as Node which would have an Object reference to hold reference to objects and a Node reference to hold a pointer to the next node in the linked list.

The linked list class would contain a member variable 'head' of type Node which would point to the head of the list.

As for the rest, you should read up on something related to Linked Lists. Read this and this.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.