Queue
A queue is a linear structure that allows insertion of elements from one end and deletion from the other. Thus it follows, First In First Out(FIFO) methodology. The end which allows deletion is known as the front of the queue and the other end is known as the rear end of the queue.
Program:
Python3
queue = [ 'first' , 'second' , 'third' ] print (queue) print () # pushing elements queue.append( 'fourth' ) queue.append( 'fifth' ) print (queue) print () # printing head print (queue[ 0 ]) # printing tail n = len (queue) print (queue[n - 1 ]) print () # popping element queue.remove(queue[ 0 ]) print (queue) |
Output:
[‘first’, ‘second’, ‘third’]
[‘first’, ‘second’, ‘third’, ‘fourth’, ‘fifth’]
first
fifth
[‘second’, ‘third’, ‘fourth’, ‘fifth’]
User Defined Data Structures in Python
In computer science, a data structure is a logical way of organizing data in computer memory so that it can be used effectively. A data structure allows data to be added, removed, stored and maintained in a structured manner. Python supports two types of data structures:
- Non-primitive data types: Python has list, set, and dictionary as its non-primitive data types which can also be considered its in-built data structures.
- User-defined data structures: Data structures that aren’t supported by python but can be programmed to reflect the same functionality using concepts supported by python are user-defined data structures. There are many data structure that can be implemented this way:
Contact Us