Last active
January 6, 2016 21:51
-
-
Save ozgurkaracam/1a808ac946cce0b49fd9 to your computer and use it in GitHub Desktop.
yığıt ile desimalden fibonacciye dönüşüm. (2014 final soru 3)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stack: | |
def __init__(self): | |
self.alist=[] | |
def pop(self): | |
return self.alist.pop() | |
def push(self,a): | |
self.alist.append(a) | |
def show(self): | |
return self.alist | |
def peek(self): | |
return self.alist[len(self.alist)-1] | |
def isempty(self): | |
return len(self.alist)==0 | |
def size(self): | |
return len(self.alist) | |
s=Stack() | |
def dec2fib(sayi): | |
s.push(1) | |
s.push(1) | |
if sayi==1 or sayi==2: | |
return 1 | |
for i in range(sayi-2): | |
a=s.pop() | |
b=s.peek() | |
s.push(a) | |
s.push(a+b) | |
return s.pop() | |
print (dec2fib(7)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment