Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help me !

Status
Not open for further replies.

0011294

Programmer
Mar 17, 2003
1
VN

Please give me Demos data structure(Linked list) with Java.
Thanh you!( mail: lovestory17@yahoo.com or nguyenanhviet1981@yahoo.com )
 
How's this.


import java.util.*;

public class LinkedListDemo {
LinkedList aLinkedList;

public LinkedListDemo() {
aLinkedList = new LinkedList();

// create some MyDataStructures;
MyDataStructure ds1 = new MyDataStructure(1, "hello", 9.9);
MyDataStructure ds2 = new MyDataStructure(6, "from", 39.9);
MyDataStructure ds3 = new MyDataStructure(34, "a", 7.5);
MyDataStructure ds4 = new MyDataStructure(50, "LinkedList", 7.1);

aLinkedList.add(ds1);
aLinkedList.add(ds2);
aLinkedList.add(ds3);
aLinkedList.add(ds4);

// Iterate through the list, printing each in turn.
Iterator it = aLinkedList.iterator();
while (it.hasNext()) {
MyDataStructure aDataStructure = (MyDataStructure)it.next();
System.out.println(aDataStructure);
}

}


public static void main(String[] args) {
LinkedListDemo linkedListDemo1 = new LinkedListDemo();
}

}

class MyDataStructure {
int number;
String msg;
double value;

public MyDataStructure(int theNumber, String theMsg, double theValue) {
number = theNumber;
msg = new String(theMsg);
value = theValue;
}

public String toString() {
return "number = "+number+" || msg = "+msg+" || value = "+value;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top