[4.2] Create Queue and Node Class | Data Structures in Python

Veröffentlicht am: 15 Dezember 2020
auf dem Kanal: ThinkX Academy
1,381
14

Implementation of Queue in Python:
Step 1) Create a Queue class and a constructor that initializes the object with front and rear as null
because initially the queue is empty.
Step 2)Create a Node class with 2 members: data and next
reference. Whenever we want to enqueue an item we will first create a Node and then assign it inside the queue.
Step 3) Enqueue(1) will enqueue the item in the queue. First, check whether the queue is empty using if self.rear==None
. If true, assign the temp node as temp = Node(data) and then assign the rear and front as temp.
If false, it means queue is not empty so perform these two steps:
1) Assign self.rear.next = temp which enqueues the temp node to the next of rear node.

2) Reassign self.rear = temp

🔗Important Links:
Data Structures in Python:    • Data Structures in Python  

🌐Join our community:
Android App(Notes+Videos): https://play.google.com/store/apps/de... Facebook:   / thinkxacademy   Twitter:   / thinkxacademy   Instagram:   / thinkxacademy  
#queue #python #dsa


Auf dieser Seite können Sie das Online-Video [4.2] Create Queue and Node Class | Data Structures in Python mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer ThinkX Academy 15 Dezember 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,381 Mal angesehen und es wurde von 14 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!