Python|Queues|Maintaining employee details

Maintaining employee details

like empno, name and salary using Queues (Using Functions)

Operations

Creation of empty queue

employee=[]

Addition of element

def add_element():
   empno=input(“Enter empno “)
   name=input(“Enter name “)
   sal=input(“Enter sal “)
   emp=(empno,name,sal)
   employee.append(emp)

Deletion of element

def del_element():
   if(employee==[]):
       print(“Underflow / Employee Queue in empty”)
   else:
       empno,name,sal=employee.pop(0)
       print(“poped element is “)
       print(“empno “,empno,” name “,name,” salary “,sal)

To check Queue is empty or not

if(employee==[]):
   print(“No Employee /Queue is empty”)
else:
   print(“Queue is not empty”)

Traversal operation

def traverse():
   if not (employee==[]):
       n=len(employee)
       for i in range(0,n):
            print(employee[i])
   else:
       print(“Empty , No employee to display”)

Source Code:

#queue implementation (using functions)
 #program to create a queue of employee(empno,name,sal).
 """
 add employee
 delete employee
 traverse / display all employees
 """
 employee=[]
 def add_element():
         empno=input("Enter empno  ")
         name=input("Enter name ")
         sal=input("Enter sal ")
         emp=(empno,name,sal)
         employee.append(emp)
 def del_element():
         if(employee==[]):
                 print("Underflow / Employee Queue in empty")
         else:
                 empno,name,sal=employee.pop(0)
                 print("poped element is ")
                 print("empno ",empno," name ",name," salary ",sal)
 def traverse():
         if not (employee==[]):
                 n=len(employee)
                 for i in range(0,n):
                         print(employee[i])
         else:
                 print("Empty , No employee to display")
 while True:
         print("1. Add element");
         print("2. Delete element");
         print("3. Traversal")
         print("4. Exit")
         ch=int(input("Enter your choice "))
         if(ch==1):
                 add_element()
         elif(ch==2):
                 del_element();
         elif(ch==3):
                 traverse()
         elif(ch==4):
                 print("End")
                 break
         else:
                 print("Invalid choice")

Visitor Counter

0056708