Upload
amardeep-kumar
View
4
Download
1
Embed Size (px)
DESCRIPTION
codes
Citation preview
Crux
Data Structures -2
Stacks and Queues
Monday, 6 July 15
Ankush Singla
Linked List doubts?
Monday, 6 July 15 2
Recursion and Pile of Books
Monday, 6 July 15 3
Stacks
Monday, 6 July 15 4
Stacks
class Stack{ // accessor methods int size(); boolean isEmpty(); Object top() throws StackEmptyException; // update methods void push (Object element); Object pop() throws StackEmptyException;
}
Monday, 6 July 15 5
How to implement Stack Class?
1. Arrays 2. Linked List
Monday, 6 July 15 6
Dynamic Arrays
Monday, 6 July 15 7
Lets Implement Our Own Stack Class Using a
Dynamic Array
Monday, 6 July 15 8
Your Turn: Implement Stack Class Using Linked List
Monday, 6 July 15 9
Lets solve few problems
1. Given an expression check if brackets are balanced e.g. { a + [ b+ (c + d)] + (e + f) }
2. Reverse a Stack with the help of another empty stack
Monday, 6 July 15 10
Queues
Monday, 6 July 15 11
Queue
class Queue{ // accessor methods int size(); boolean isEmpty(); Object front() throws QueueEmptyException; // update methods void enqueue(Object element); Object dequeue() throws QueueEmptyException;
}
Monday, 6 July 15 12
How to implement Queue Class?
1. Linked List 2. Arrays
Monday, 6 July 15 13
Lets Implement Our Own Queue Class Using Arrays
Monday, 6 July 15 14
Your Turn: Implement Queue Class Using Linked List
Monday, 6 July 15 15
Lets solve few problems
1. Reverse a Queue 2. Implement a Stack using Two Queues
Monday, 6 July 15 16
Everyone Done with this?
Given a integer input find number of permutations of input which are greater than input. e.g. Input 123 -> Output = 5
Monday, 6 July 15 17