0% found this document useful (0 votes)
15 views1 page

Python Code

Uploaded by

seralathan s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Python Code

Uploaded by

seralathan s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

class ListNode:

def __init__(self, val):


self.val = val
self.next = None

class Queue:
# Implementing this with dummy nodes would be easier!
def __init__(self):
self.left = self.right = None

def enqueue(self, val):


newNode = ListNode(val)

# Queue is non-empty
if self.right:
self.right.next = newNode
self.right = self.right.next
# Queue is empty
else:
self.left = self.right = newNode

def dequeue(self):
# Queue is empty
if not self.left:
return None

# Remove left node and return value


val = self.left.val
self.left = self.left.next
return val

def print(self):
cur = self.left
while cur:
print(cur.val, ' -> ', end ="")
cur = cur.next
print() # new line

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy