Created
November 27, 2012 15:57
-
-
Save naimakin/4155034 to your computer and use it in GitHub Desktop.
pyton datastruct
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.items = [] | |
| def isEmpty(self): | |
| return self.items == [] | |
| def push(self,item): | |
| self.items.append(item) | |
| def pop(self.item): | |
| return self.items.pop() | |
| def peek(self): | |
| return self.items[len(self.items)-1] | |
| def size(self): | |
| return len(self.items) | |
| def conventer(number,base): | |
| digits = "0123456789ABCDEF" | |
| k=Stack() | |
| while number>0: | |
| n=number%base | |
| k.push(n) | |
| number = number%base | |
| string="" | |
| while not k.isEmpty(): | |
| string = string + digits[k.pop()] | |
| return string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment