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.items = [] | |
| def enqueue(self, item): | |
| self.items.append(item) | |
| def dequeue(self): | |
| return self.items.pop(0) |
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 queue import * | |
| class Node: | |
| def __init__(self, val): | |
| self.data = val | |
| self.left = None | |
| self.right = None | |
| def insert(self, val): | |
| if val < self.data: |
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 Node: | |
| def __init__(self, val): | |
| self.data = val | |
| self.next = None | |
| self.prev = None | |
| class LinkedList: | |
| def __init__(self): | |
| self.head = None | |
| self.tail = None |
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
| ## Basic Sorting Algorithms | |
| def bubleSort(lst): | |
| n = len(lst) | |
| for i in range(n-1): | |
| for j in range(n-1-i): | |
| if lst[j]>lst[j+1]: | |
| tmp = lst[j+1] | |
| lst[j+1] = lst[j] | |
| lst[j] = tmp |
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 push(self, item): | |
| self.items.append(item) | |
| def pop(self): | |
| return self.items.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 Stack: | |
| def __init__(self): | |
| self.items = [] | |
| def push(self, item): | |
| self.items.append(item) | |
| def pop(self): | |
| return self.items.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 Stack: | |
| def __init__(self): | |
| self.items = [] | |
| def push(self, item): | |
| self.items.append(item) | |
| def pop(self): | |
| return self.items.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 Graph: | |
| def __init__(self): | |
| self.dic = {} | |
| def addVertex(self, vert): | |
| if vert not in self.dic: | |
| self.dic[vert] = [] | |
| def addEdge(self, start, end): | |
| if end not in self.dic[start]: |
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 Graph: | |
| def __init__(self): | |
| self.dic = {} | |
| def addVertex(self, vert): | |
| if vert not in self.dic: | |
| self.dic[vert] = [] | |
| def addEdge(self, start, end): | |
| if end not in self.dic[start]: |
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 Vertex: | |
| def __init__(self, value): | |
| self.value = value | |
| self.adjacents = [] | |
| self.state = 0 | |
| class Graph: | |
| def __init__(self): | |
| self.vertices = [] | |
| # self.edges = [] |
OlderNewer