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