The document discusses data structures and their implementation. It describes simple and compound data structures, including linear structures like stacks and queues. It provides details on operations for stacks and queues and includes Python code to implement each using lists.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
31 views5 pages
Data Structure
The document discusses data structures and their implementation. It describes simple and compound data structures, including linear structures like stacks and queues. It provides details on operations for stacks and queues and includes Python code to implement each using lists.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5
DATA-STRUCTURE
Data Structure :- represents how data is stored in computer’s
memory. Implementation of Data Structure can be done by two ways:- 1. Simple Data Structure:-Built from primitive data types such as (integer,real,character,Boolean) For example Arrays or Linear list 2. Compound Data Structure:-Simple Data Structure are used to form more complex data structure. They are classified into two types:- a. Linear:-when elements are stored in sequential order. Example Stack, Queue, Linked list b. Non Linear :- When data is stored as multilevel structure. Example Trees, Graphs Stack:- ● It is a linear data structure ● It is a list of elements in which an element may be inserted or deleted only at one end called TOP of the stack ● It follows LIFO means last in first out. The element inserted last would be the first to be deleted Operations performed on stack are: a. PUSH(ADDITION) b. POP(DELETION) c. DISPLAY PUSH Initially stack is -1
Overflow: It refers to a situation , when one tries to push an element
in a stack/queue that is full. Underflow: It refers to a situation , when one tries to delete an element in a stack/queue that is empty. Queue ● It is linear data structure ● It is a list of elements in which insertion takes place at one end called the rear ● Deletion takes place at the other end called the front ● It follows FIFO means first in first out. The element inserted first would be the first to get removed Basic operations performed on queue are:- Enqueue:-Insert the element in queue Dequeue:- Delete the element from queue 23 45 78 89 78 67 70 F,R R R R R R R 0 1 2 3 4 5 6 89 78 67 70 0 1 2 3 4 5 6
#Implementation of stack using list
def stack(): stack=[] choice='y' while choice=='y': print("1. PUSH") print("2. POP") print("3. DISPLAY") print("4. EXIT") ch=int(input("Enter your choice")) if ch==1: num=int(input("enter element which you want to add")) stack.append(num) print("Element added successfully...") elif ch==2: if stack==[]: print("Stack is empty.... underflow") else: print("Deleted element is :",stack.pop()) elif ch==3: if stack==[]: print("Stack is empty.... underflow") else: for i in range(len(stack)-1,-1,-1): print(stack[i]) else: break choice=input("do u want to continue") stack()
#Implementation of queue using list
def queue(): queue=[] choice='y' while choice=='y': print("1. PUSH") print("2. POP") print("3. DISPLAY") ch=int(input("Enter your choice")) if ch==1: num=int(input("enter element which you want to add")) queue.append(num) print("Element added successfully...") elif ch==2: if queue==[]: print("queue is empty.... underflow") else: print("Deleted element is :",queue.pop(0)) elif ch==3: if queue==[]: print("Queue empty.... underflow") else: for i in range(len(queue)): print(queue[i]) else: print("wrong choice") choice=input("do u want to continue y\n") if choice!='y': break queue()