-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5feb4f4
commit 7fd4376
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
class Node: | ||
def __init__(self, val): | ||
self.val = val | ||
self.next = None | ||
self.prev = None | ||
|
||
|
||
class CircularLinkedList: | ||
def __init__(self): | ||
self.main = None | ||
self.head = False | ||
|
||
def append_(self, val): | ||
if self.main is None: | ||
self.main = Node(val) | ||
self.main.head = True | ||
self.main.prev = self.main | ||
return | ||
temp = self.main.prev | ||
temp.next = Node(val) | ||
temp.next.prev = temp | ||
temp.next.next = self.main | ||
|
||
def prepend_(self, val): | ||
temp = self.main.prev | ||
temp.next = Node(val) | ||
temp.next.head = True | ||
self.main.head = False | ||
self.main = temp.next | ||
|
||
def print_(self): | ||
temp = None | ||
if self.main is None: | ||
print("Circular Linked List is Empty") | ||
return | ||
else: | ||
temp = self.main | ||
print(" ʌ".center(12)) | ||
print("| |".center(12)) | ||
print("V ".center(12)) | ||
while temp is not None: | ||
print("_" * 12) | ||
print("|" + f"{temp.val}".center(10) + "|") | ||
print("־" * 12) | ||
print(" ʌ".center(12)) | ||
print("| |".center(12)) | ||
print("V ".center(12)) | ||
temp = temp.next | ||
|
||
|
||
if __name__ == "__main__": | ||
cll = CircularLinkedList() | ||
cll.append_(1) | ||
cll.append_(2) | ||
cll.append_(2) | ||
cll.append_(3) | ||
cll.prepend_(0) | ||
cll.print_() |