求助,java 编程,链表问题
链表,是数据结构里最为重要的概念之一。怎样用最简单的方法,写一个单链表,输出结果。参数是int 或 String 随机给入,并输出结果,
多谢了。
$握手$$握手$ 我虽然是编c的,不过从纯编程的角度,从你的描述不明白你要干嘛。 哦 不好意思,本人是初学者 。:P
创建一个单链表,然后给出链表的所有结点的值。
数据类型可以是 int型也可以是 String 型的。
class List{
int datei;
List next;
List(int a, List nn){
datei=a; next=nn;}
List(int a){
datei=a; next=null;}
}
我的问题是怎样输出链表谢谢$握手$
[ 本帖最后由 Bajie 于 2006-6-23 14:05 编辑 ] speaking of output:
1. create a pointer points to an instance of the class "List".
for instence:
List* p;
p=my_list;//my_list is the instance, should be already created and filled with the data.
2. while loop
while(p->next) {
printf("data=%d\n",p->datei);
p=p->next;
}
above is c++ style, in Java the syntax might be changed, but i think the prinzip is the same.
p.s. I think, you mean "data" instead of "datei"
D -- E
Datei - file
Daten - data Java里面直接有LinkedList类。最简单的办法就是直接用LinkedList<String>或者LinkedList<Integer> 原帖由 cosimo 于 2006-6-23 16:34 发表
speaking of output:
1. create a pointer points to an instance of the class "List".
for instence:
List* p;
p=my_list;//my_list is the instance, should be already created and filled w ...
C的看太不懂。$考虑$ 我再研究研究。 谢了。
页:
[1]