Created
January 6, 2016 20:55
-
-
Save ozgurkaracam/f12b5f89eae49066ca3c to your computer and use it in GitHub Desktop.
denemeler
This file contains 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 Dequeue: | |
def __init__(self): | |
self.items=[] | |
def addRear(self,a): | |
self.items.insert(0,a) | |
def addFront(self,a): | |
self.items.append(a) | |
def isempty(self): | |
return self.items==[] | |
def removeFront(self): | |
self.items.pop() | |
def removeRear(self): | |
self.items.pop(0) | |
def size(self): | |
return len(self.items) | |
class Stack(Dequeue): | |
def __init__(self): | |
Dequeue.__init__(self) | |
def pop(self): | |
self.items.pop(0) | |
def push(self,a): | |
self.addRear(a) | |
def peek(self): | |
return self.items[0] | |
def yigitaynimi(s1,s2): #iki yığıtınaynı olup olmadığını veren özyineli (recursive) fonksiyon | |
if s1.isempty() and s2.isempty(): | |
return True | |
elif s1.size()!=s2.size(): | |
return False | |
elif s1.pop()==s2.pop(): | |
return yigitaynimi(s1,s2) | |
else: | |
return False | |
s1=Stack() | |
s2=Stack() | |
s1.push(1) | |
s1.push(2) | |
s1.push(3) | |
s1.push(4) | |
s2.push(1) | |
s2.push(2) | |
s2.push(3) | |
s2.push(333) | |
print (yigitaynimi(s1,s2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment