java没有指针怎么处理链表_Java,Python中没有指针,怎么实现链表,图等数据结构...

package com.list;

public class Node {

private Node next;

private T data;

public Node(){

this(null, null);

}

public Node(Node next, T data){

this.next = next;

this.data = data;

}

public Node getNext() {

return next;

}

public void setNext(Node next) {

this.next = next;

}

public T getData() {

return data;

}

public void setData(T data) {

this.data = data;

}

@Override

public String toString() {

return "Node " +  ", data=" + data;

}

}package com.list;

public class List  {

private Node head;

private Node tail;

private Node current;

public void createList(T[] data){

//List list = new List();

for (int i = 0; i 

Node temp = new Node(null, data[i]);

if (0 == i){

head = temp;

current = temp;

continue;

}

tail = temp;

current.setNext(temp);

current = temp;

}

//return list;

}

public List(){

head = null;

tail = null;

}

public Node getHead() {

return head;

}

public void setHead(Node head) {

this.head = head;

}

public Node getTail() {

return tail;

}

public void setTail(Node tail) {

this.tail = tail;

}

private void print(){

current = head;

while (current != null){

System.out.println(current.toString());

current = current.getNext();

}

}

public static void main(String[] args) {

Integer[] data = new Integer[5];

for (int i = 0; i

data[i] = i + 10;

}

List temp = new List();

temp.createList(data);

temp.print();

}

}

温馨提示:答案为网友推荐,仅供参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值