자료구조 | Singly Linked List | Linked List (tistory.com)
위 글에서 Singly Linked List 클래스 내부 함수를 활용하였다.
Double Ended Queue
• add_front
• add_rear
• pop_front
• pop_rear
import random
class Node:
def __init__(self, item):
self.data = item
self.link = None
class SLL:
def __init__(self):
self.head = None
self.rear = None
self.count = 0
def isEmpty(self):
return self.head == None
def addFront(self, node):
tmp = self.head
self.head = node
node.link = tmp
if self.count == 0:
self.rear = self.head
self.count += 1
def addRear(self, node):
tmp = self.rear
self.rear = node
self.rear.link = tmp
if self.count == 0:
self.head = self.rear
self.count += 1
def popFront(self):
tmp = self.head.data
self.head = self.head.link
self.count -= 1
return tmp
def popRear(self):
tmp = self.rear.data
del tmp
self.count -= 1
return tmp
def print(self):
tmp = self.head
while True:
if tmp == None:
break
else:
print(tmp.data)
tmp = tmp.link
s = SLL()
for i in range(10):
tmp = Node(i*100)
s.addFront(tmp)
s.print()
'Computer Science > 자료구조' 카테고리의 다른 글
자료구조 | Binary Search | Search (0) | 2021.12.29 |
---|---|
자료구조 | Sequential Search | Search (0) | 2021.12.29 |
자료구조 | Linked Queue, Linked Stack | Linked Lists (0) | 2021.12.29 |
자료구조 | Singly Linked List | Linked List (0) | 2021.12.29 |
자료구조 | Maze Problem | linear DS (0) | 2021.12.29 |