Skip to main content

Data Structure


two ways: linear and non linear
Linear : list, stack, queue, array , link list
Non Linear : tree , graph
Stack : is a linear list  where insertion and deletion occurs from same end called TOP of the stack . Stack is also called LIFO. Stack has no variant. Stack can be implemented in Python using list.
Stacks


what is the basic difference between stack and queue? - Stack OverflowJavaScript — Stacks and Queues - Dhara Patel - Medium
Use of stack:
Reverse a word/line
Evaluate the math 
nested function calling/ Backtracking

Queue: is a linear list where insertion occurs from rear end and deletion from front end. Queue is also called FIFO. There are three types of Queue  ordinary queue, double ended queue and circular Queue. List can be implemented in Python using list

Use of Queue: 


Common operations performed on Data structure
insertion/deletion/Display(traversal)/Searching /sorting



Queue Operations in Python


def push(list,item):
    list.append(item)

def pushitem(list):
    item=int(input("Enter value"))
    list.append(item)

def popitem(list):
    if(list==[]):
        print("Queue is empty")
    else:
        print("Deleted item",list[0])
        del(list[0])

def display(list):
    if(list==[]):
        print("Queue is empty")
    else:
        
        for i in  list:
            print(i)


Stack Operations in Python


list=[ ]

def push(list):
    item=int(input("Enter value"))
    list.append(item)

def popitem(list):
    if(list==[]):
        print("Stack is empty")
    else:
       print("Deleted item",list.pop())

def display(list):
  if(list==[]):
      print("stack is empty")
  else:
     print(list[::-1])
                        
n=int(input("Enter Your choice 1.push 2.pop 3.display 4.exit "))               
while(n!=4):
  if(n==1):
    push(list)
  elif (n==2):
    popitem(list)
  elif(n==3):
    display(list)
  else:
    break
  n=int(input("Enter Your choice 1.push 2.pop 3.display 4.exit "))






























Comments

Popular posts from this blog

Revision basics of Python covered in Class XI

Reading Text Files

Writing CSV Files