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 Deque(): | |
| """Deque DST""" | |
| def __init__(self): | |
| self._items = [] | |
| def add_front(self, item): | |
| """ | |
| Add to the front | |
| """ |
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
| import bisect | |
| from heapq import * | |
| """ | |
| Linked Lists | |
| A linked list is an ordered collection of values. | |
| Linked lists are similar to arrays in the sense that they contain objects in a linear order. | |
| However they differ from arrays in their memory layout. |
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
| """ | |
| Strings are immutable sequence of characters | |
| http://thomas-cokelaer.info/tutorials/python/strings.html | |
| https://docs.python.org/3/library/stdtypes.html#string-methods | |
| """ | |
| class Strings(): | |
| def __init__(self, elem): | |
| self.elem = elem |
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 Dicts(): | |
| def __init__(self, elem): | |
| self.elem = elem | |
| def len(self): | |
| return len(self.elem) | |
| def keys(self): | |
| return self.elem.keys() |
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
| """ | |
| A tuple is similar to a list. The difference between the two is that we cannot change the elements of a tuple once | |
| it is assigned whereas in a list, elements can be changed. | |
| - We generally use tuple for heterogeneous (different) datatypes and list for homogeneous (similar) datatypes. | |
| - Since tuple are immutable, iterating through tuple is faster than with list. So there is a slight performance boost. | |
| - Tuples that contain immutable elements can be used as key for a dictionary. With list, this is not possible. | |
| - If you have data that doesn't change, implementing it as tuple will guarantee that it remains write-protected. | |
| https://www.programiz.com/python-programming/tuple |
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
| from heapq import * | |
| class Heap(): | |
| def __init__(self): | |
| self.heap = [] | |
| def heappush(self, item): | |
| """Push the value item onto the heap, maintaining the heap invariant.""" | |
| heappush(self.heap, item) |
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.stack = [] | |
| def pushCharacter(self, char): | |
| self.stack.append(char) | |
| def popCharacter(self): | |
| return self.stack.pop() |
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 Queue(): | |
| def __init__(self): | |
| self.queue = [] | |
| def enqueueCharacter(self, char): | |
| self.queue.insert(0, char) | |
| def dequeueCharacter(self): | |
| return self.queue.pop() |
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
| import bisect | |
| from heapq import * | |
| class Lists(): | |
| def __init__(self, elem): | |
| self.elem = elem | |
| def append(self, x): |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.