Demo For Comsats
Demo For Comsats
Demo For Comsats
MS COMPUTER SCIENCE
DATA STRUCTURES
TABLE OF CONTENT
1. Data Structure
2. Types of Data
3. Classification of Data Structure
4. Stack
5. Queue
WHY WE NEED TO ORGANIZE OR
STRUCTURE?
• Data: Collection of raw facts
• Data Structure is a representation of logical relationship existing between individual
elements of data.
• Data structure is a specialized format for organzing and storing data in memory that
considers not only the elements stored but also their relationship to each other.
• Affects the structural and functional aspects of a program.
• Program = Algorithm + Data Structure
CATEGORIES OF DATA STRUCTURE
• Primitive Data Structure: directly operated upon the machine level instructions. E.g
Integers, float, character, pointers.
• Arrays: Static
• Pointers: Dynamic (DFS)
OPERATIONS:
• Stack(): it creates a new stack that is empty. It needs no parameters and returns an empty stack.
• push(obj): Add object obj at the top of the stack.
• Obj Pop():it removes the top item from the stack.
• Obj peek(): it removes the top item from the stack but doesn’t remove.
• isEmpty(): it test whether the stack is empty.
• isFull(): it test whether the stack is empty.
• Size(): it returns the number of items on the stack.
STACK IMPLEMENTATION
• class Stack {
int top;
boolean isEmpty()
• Stack()
top = -1;
}
INSERTION
boolean push(int x)
{
if (top >= (MAX - 1)) {
System.out.println("Stack Overflow");
return false;
}
else {
a[++top] = x;
System.out.println(x + " pushed into stack");
return true;
}
}
DELETION
int pop()
{
if (top < 0) {
System.out.println("Stack Underflow");
return 0;
}
else {
int x = a[top--];
return x;
}
}
PEEK VALUE: RETURN
int peek()
{
if (top < 0) {
System.out.println("Stack Underflow");
return 0;
}
else {
int x = a[top];
return x;
}
}
}
DRIVER CODE
Main {
public static void main(String args[])
{
Stack s = new Stack();
s.push(10);
s.push(20);
s.push(30);
System.out.println(s.pop() + " Popped from stack")
}
}
APPLICATIONS OF STACK:
• Arrays: Static
• Pointers: Dynamic
TYPES OF QUEUE
• Simple Queue
• Circular Queue
• Priority Queue
• Double ended Queue
OPERATIONS