python如何实现类似指针概念_python这么通过类似指针的方式实现循环链表

2014-03-05 回答

package com.list; public class node<t extends number> { 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 <t extends number> { private node<t> head; private node<t> tail; private node<t> current; public void createlist(t[] data){ //list<t> list = new list<t>(); for (int i = 0; i < data.length; i++){ node<t> temp = new node<t>(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<t> gethead() { return head; } public void sethead(node<t> head) { this.head = head; } public node<t> gettail() { return tail; } public void settail(node<t> 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.length; i++){ data[i] = i + 10; } list<integer> temp = new list<integer>(); temp.createlist(data); temp.print(); } }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值