![]() ![]() It will only contain one element – 20 at the second position. To that, we shall first add two items – 10 and 20 and then perform a dequeue operation once. Now, we shall create a queue class object named ‘queue1’. To demonstrate what I consider useless behaviour, I have the following test file called Test1. The number of bytes returned may be less or more than requested. At most one single read on the raw stream is done to satisfy the call. We also have a print_queue() function for printing the queue. peek ( size) Return bytes from the stream without advancing the position. Then, we shall increment ont and self.available by one. Else, we would assign the queue item at the ‘front’ index back to ‘None’. If it is, then it means that the queue is empty, and so it will print Queue Underflow. First, we shall check if the self.available is equal to self.size or not. The dequeue function takes one argument, which is self. Then, we shall increment ‘rear’ by one and decrement ‘available’ by one. Otherwise, using the ‘rear’ as in index, we shall assign the value ‘item’ at that index. If self.available is zero, then we would print ‘Queue Overflow’. First, we check whether the queue contains any available space or not. The enqueue function takes two arguments – self and the item to be inserted in the queue. To preform dequeue operation, we have to use the ‘Front’ to access the topmost element from the queue in order to pop it. If the queue is empty, then we shall specify an ‘Underflow’ condition else we shall pop an element. While performing dequeue, we will first check if the queue is empty or not. Dequeue : The dequeue operation is used to pop elements from the queue.To perform enqueue operation, we have to use ‘Rear’ as new elements are added from the rear end of the queue. Only if the queue is has space, we will conduct an enqueue operation. Before performing an enqueue operation, we will have to check whether the queue is full or not. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |