python实现的链表
来源:互联网 发布:淘宝联盟微信推广技巧 编辑:程序博客网 时间:2024/06/06 12:42
python实现的链表,包括插入、查找、删除操作
#!/usr/bin/python class linknode():def __init__(self,k,n=None):self.key=k;self.next=n;def createlist(): #创建链表n=raw_input("enter the num of nodes");n=int(n);if n<1 :return ;else :a=raw_input("enter the key");head=linknode(k=a);if n is 1:return head;else :p=head;for i in range(1,n):a=raw_input("enter a key");t=linknode(k=a);p.next=t;p=t;return head;def printlist(head): #打印链表p=head;while p!= None:print p.key;p=p.next;def listlen(head): #计算链表长度c=0;p=head;while p!= None:c=c+1;p=p.next;return c;def insert(head,n): #插入元素if n<1 or n>listlen(head) :return ;p=head;if n is 1:a=raw_input("enter a key");t=linknode(k=a);t.next=head;head=t;else :for i in range(1,n-1):p=p.next;a=raw_input("enter a key");t=linknode(k=a);t.next=p.next;p.next=t;return head; def dellist(head,n): #删除if n<1 or n>listlen(head):return head;elif n is 1:head=head.next;else:p=head;for i in range(1,n-1):p=p.next;q=p.next;p.next=q.next;return head;def findlist(head,n): # 查找p=head;if p is None:return ;while(p!=None):if p.key is repr(n):print "find it";return 1;else:p=p.next;if p is None:print "not found";
0 0
- python实现的链表
- python实现的链表
- Python链表的实现
- Python 链表的实现
- 链表的python实现
- Python 实现简单的单向链表
- python的链表定义以及实现
- 单向链表的Python实现
- python 关于循环链表的实现
- python实现链表
- Python实现链表
- 跳表的python实现
- Python实现的内存表
- Python 实现单向链表
- python实现单向链表
- python实现双向链表
- Python 实现单向链表
- python实现链表增删
- linux的echo命令
- A*
- 操作系统学习总结四
- 发现新浪一注册漏洞
- Java 自定义窗体(标题栏、窗体背景)
- python实现的链表
- Cacti监控MySQL实现过程中碰到的问题解汇总
- 数据库web交互
- 技术的三重境界
- 工作日志 6/6/2014 .net URL 特殊符号 escaping的问题
- 轻松解决oracle11g 空表不能 exp 导出 的问题
- 黑马程序员—JAVA基础之网络编程
- java xfire 调用C#编写webService
- 为什么我要以写代码为生?