Skip to content

Commit 0475ea6

Browse files
committed
eiei
1 parent b3b0543 commit 0475ea6

10 files changed

+401
-0
lines changed

Diff for: .lab7_1.py.swp

12 KB
Binary file not shown.

Diff for: .lab7_1.py.un~

78.7 KB
Binary file not shown.

Diff for: .linkedlist.py.un~

11.7 KB
Binary file not shown.

Diff for: 1

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class node:
2+
def __init__(self,data):
3+
self.data = data
4+
self.next = None
5+
6+
class linkedlist:
7+
def __init__(self):
8+
self.head = self.tail = None
9+
10+
def __str__(self):
11+
output =''
12+
n = self.head
13+
while n is not self.tail:
14+
output += n.data
15+
n = n.next
16+
output+=n.data
17+
return output
18+
def append(self,data):
19+
if self.head == None:
20+
self.head = node(data)
21+
self.tail = self.head
22+
else:
23+
tail = self.tail
24+
tail.next = node(data)
25+
self.tail = tail.next
26+
x = linkedlist()
27+
x.append('a')
28+
x.append('b')
29+
x.append('c')
30+
print(x)

Diff for: lab5_1.py

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
class node:
2+
def __init__(self,data,nexts = None):
3+
self.data = data
4+
self.nexts = nexts
5+
6+
def __str__(self):
7+
return self.data
8+
9+
class List:
10+
11+
def __init__(self,data = None):
12+
self.head = self.tail = node(data)
13+
self.size = 0 if data == None else 1
14+
def __str__(self):
15+
p = self.head
16+
while p.nexts != None:
17+
print(p.data,end=' ')
18+
p = p.nexts
19+
print(p.data)
20+
return ''
21+
22+
def isEmpty(self):
23+
return self.size == 0
24+
25+
def append(self,data):
26+
p = node(data)
27+
if self.head.data == None:
28+
self.head = p
29+
self.tail = self.head
30+
self.tail.nexts = p
31+
self.tail = p
32+
self.size += 1
33+
34+
def addHead(self,data):
35+
p = node(data,self.head)
36+
self.head = p
37+
self.size +=1
38+
39+
def isIn(self,data):
40+
t = self.head
41+
while t.nexts != None:
42+
if t.data == data:
43+
return True
44+
t = t.nexts
45+
if t.data == data:
46+
return True
47+
return False
48+
49+
def before(self,data):
50+
before = None
51+
i = self.head
52+
while i.nexts != None:
53+
if i.data == data:
54+
return before
55+
before = i
56+
i = i.nexts
57+
if i.data == data:
58+
return before
59+
return None
60+
61+
# def remove(self,data):
62+
# if not self.isIn(data) or self.before(data) == None:
63+
# print('Failed to remove')
64+
# return
65+
# self.before(data).nexts = self.before(data).nexts.nexts
66+
67+
def remove(self,index):
68+
currentNode = self.get(index-1)
69+
currentNode.nexts= self.get(index+1)
70+
def removeTail(self):
71+
t = self.before(self.tail.data)
72+
t.nexts = None
73+
self.tail = t
74+
75+
def removeHead(self):
76+
self.head = self.head.nexts
77+
78+
def get(self,index):
79+
if index > self.size:
80+
raise IndexError
81+
t = self.head
82+
for i in range(index):
83+
t = t.nexts
84+
if t != None:
85+
return t
86+
87+
def insert(self,node,index):
88+
currentNode = self.get(index)
89+
nextNode = currentNode.nexts
90+
91+
currentNode.nexts = node
92+
node.nexts = nextNode
93+
94+
95+
class Poke(List):
96+
def __init__(self,start,end):
97+
List.__init__(self,)
98+
for i in range(start,end+1):List.append(self,str(i))
99+
def bottomUp(self,factor):
100+
if factor <= 0 or factor >= 1:
101+
raise IOError('factor must in range 0 - 1')
102+
sizeBottomUp =int(self.size*factor)
103+
newTail = self.get(sizeBottomUp)
104+
newHead = newTail.nexts
105+
oldHead = self.head
106+
oldTail = self.tail
107+
oldTail.nexts = oldHead
108+
self.tail = newTail
109+
self.tail.nexts = None
110+
self.head = newHead
111+
def deBottomUp(self,factor):
112+
if factor <= 0 or factor >= 1:
113+
raise IOError('factor must in range 0 - 1')
114+
sizeDeBottomUp = int(self.size*factor)
115+
newTail = self.get(self.size - sizeDeBottomUp)
116+
newHead = self.get(self.size - sizeDeBottomUp + 1)
117+
self.tail.nexts = self.head
118+
self.head = newHead
119+
self.tail = newTail
120+
newTail.nexts = None
121+
122+
def riffle(self,factor):
123+
if factor <= 0 or factor >= 1:
124+
raise IOError('factor must in range 0 - 1')
125+
cutIndex = int(self.size * factor)
126+
127+
self.tail = self.get(cutIndex)
128+
# self.tail.nexts = None
129+
for i in range(0,self.size - cutIndex):
130+
insertNode = node(self.get( i + cutIndex ).data)
131+
self.remove(i+cutIndex)
132+
self.insert(insertNode,i*2)
133+
134+
def deRiffle(self,factor):
135+
if factor <= 0 or factor >= 1:
136+
raise IOError('factor must in range 0 - 1')
137+
138+
139+
140+
141+
142+
143+
poke = Poke(1,10)
144+
poke.riffle(0.6)
145+
print(poke)
146+
#poke.bottomUp(0.3)
147+
# poke.riffle(0.6)
148+
# print(poke)

Diff for: lab7_1.py

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
def printNdown(n):
2+
if n==1:
3+
print(n,end=' ')
4+
else:
5+
print(n)
6+
printNdown(n-1)
7+
8+
def printToN(n):
9+
if n==1:
10+
print(n ,end= ' ')
11+
else:
12+
printToN(n-1)
13+
print(n,end=' ')
14+
15+
def sumToN(n):
16+
if n==1:
17+
return 1
18+
else:
19+
return n+sumToN(n-1)
20+
21+
def printForw(lists):
22+
if len(lists) != 0:
23+
return str(lists.pop(0)) + str(printForw(lists))
24+
else:return ''
25+
26+
def printBack(lists):
27+
if len(lists) != 0:
28+
return str(lists.pop()) + str(printBack(lists))
29+
else:return ''
30+
31+
class node:
32+
def __init__(self,data):
33+
self.data = data
34+
self.next = None
35+
def __str__(self):
36+
return self.data
37+
38+
class lists:
39+
def __init__(self,lists_head = None):
40+
if lists_head == None:
41+
self.head = self.tail = None
42+
else:
43+
self.head = node(lists_head.pop(0))
44+
n = self.head
45+
while len(lists_head) != 0:
46+
n.next = node(lists_head.pop(0))
47+
self.tail = n
48+
n = n.next
49+
50+
def __str__(self):
51+
output = ''
52+
n = self.head
53+
while n.next != None:
54+
print(n.data,end=' ')
55+
n = n.next
56+
print(n.data)
57+
return ''
58+
59+
def fibo(n):
60+
if n==1 or n==2:
61+
return 1
62+
else:
63+
return fibo(n-1) + fibo(n-2)
64+
print(fibo(20))
65+
x = lists([1,2,3,4,5])
66+
67+
#print(x)
68+
69+
70+
#printNdown(5)
71+
#printToN(5)
72+
#print(sumToN(10))
73+
#print(printForw([1,2,3,4,5]))
74+
#print(printBack([1,2,3,4,5]))

Diff for: lab7_1.py~

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
def printNdown(n):
2+
if n==1:
3+
print(n,end=' ')
4+
else:
5+
print(n)
6+
printNdown(n-1)
7+
8+
def printToN(n):
9+
if n==1:
10+
print(n ,end= ' ')
11+
else:
12+
printToN(n-1)
13+
print(n,end=' ')
14+
15+
def sumToN(n):
16+
if n==1:
17+
return 1
18+
else:
19+
return n+sumToN(n-1)
20+
21+
def printForw(lists):
22+
if len(lists) != 0:
23+
return str(lists.pop(0)) + str(printForw(lists))
24+
else:return ''
25+
26+
def printBack(lists):
27+
if len(lists) != 0:
28+
return str(lists.pop()) + str(printBack(lists))
29+
else:return ''
30+
31+
class node:
32+
def __init__(self,data):
33+
self.data = data
34+
self.next = None
35+
def __str__(self):
36+
return self.data
37+
38+
class lists:
39+
def __init__(self,lists_head = None):
40+
if lists_head == None:
41+
self.head = self.tail = None
42+
else:
43+
self.head = node(lists_head.pop(0))
44+
n = self.head
45+
while len(lists_head) != 0:
46+
n.next = node(lists_head.pop(0))
47+
self.tail = n
48+
n = n.next
49+
50+
def __str__(self):
51+
output = ''
52+
n = self.head
53+
while n.next != None:
54+
print(n.data,end=' ')
55+
n = n.next
56+
print(n.data)
57+
return ''
58+
59+
def fibo(n):
60+
if n==1 or n==2:
61+
return 1
62+
else:
63+
return fibo(n-1) + fibo(n-2)
64+
print(fibo(10))
65+
x = lists([1,2,3,4,5])
66+
67+
#print(x)
68+
69+
70+
#printNdown(5)
71+
#printToN(5)
72+
#print(sumToN(10))
73+
#print(printForw([1,2,3,4,5]))
74+
#print(printBack([1,2,3,4,5]))

Diff for: linkedlist.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class node:
2+
def __init__(self,data):
3+
self.data = data
4+
self.next = None
5+
6+
class linkedlist:
7+
def __init__(self):
8+
self.head = self.tail = None
9+
10+
def __str__(self):
11+
output =''
12+
n = self.head
13+
while n is not self.tail:
14+
output += ' ' + str(n.data)
15+
n = n.next
16+
output+=' ' + str(n.data)
17+
return output
18+
def append(self,data):
19+
if self.head == None:
20+
self.head = node(data)
21+
self.tail = self.head
22+
else:
23+
tail = self.tail
24+
tail.next = node(data)
25+
self.tail = tail.next
26+
x = linkedlist()
27+
x.append('a')
28+
x.append('b')
29+
x.append('c')
30+
print(x)

Diff for: linkedlist.py~

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class node:
2+
def __init__(self,data):
3+
self.data = data
4+
self.next = None
5+
6+
class linkedlist:
7+
def __init__(self):
8+
self.head = self.tail = None
9+
10+
def __str__(self):
11+
output =''
12+
n = self.head
13+
while n is not self.tail:
14+
output += ' ' + str(n.data)
15+
n = n.next
16+
output+=n.data
17+
return output
18+
def append(self,data):
19+
if self.head == None:
20+
self.head = node(data)
21+
self.tail = self.head
22+
else:
23+
tail = self.tail
24+
tail.next = node(data)
25+
self.tail = tail.next
26+
x = linkedlist()
27+
x.append('a')
28+
x.append('b')
29+
x.append('c')
30+
print(x)

0 commit comments

Comments
 (0)