2018-08-01
2018-08-01 本文已影响0人
Jeese_zhao
Python部分
- 1.元组属于不可变对象,列表属于可变对象,列表的很多方法不适用于元组;元组可哈希而列表不可哈希
- 2.cloudranA = ['1', '2', '3', '4', '4', '5']
- 3.cloudranA = list(set(cloudran))
cloudranA = ['4', '5', '3', '1', '2'] - 实现一个队列 如下
# coding:utf-8
# 首先获取节点,包含next指针和该节点位置上元素的值
class Node(object):
def __init__(self, val):
self.next = None
self.val = val
class Queue(object):
def __init__(self):
self.first = None
self.last = None
# 进队操作
def enter(self, n):
# 实例节点
n = Node(n)
# 进队之前先判断队列是否为空,即判断first是否为None
if self.first == None:
# 此时last==first==n
self.first = n
self.last = self.first
else:
# 将last的指针设置为n,值设置为n
self.last.next = n
self.last = n
# 出队
def quit(self):
if self.first == None:
return None
else:
tmp = self.first.val
self.first = self.first.next
return tmp
# 保存队列元素到列表
def allQuit(self):
Lists = []
while self.first != None:
Lists.append(self.first.val)
self.first = self.first.next
return Lists
if __name__ == '__main__':
q = Queue()
q.enter(1)
q.enter(2)
q.enter(3)
# print(q.quit())
# print(q.quit())
# print(q.quit())
# print(q.quit())
print(q.allQuit())