Вы находитесь на странице: 1из 18

MODULE 1

DATA STRCUTURES
DATA STRUCTURE

 A data structure is a way of organizing


data so that it can be used efficiently. In
C language, different types of data
structures are; Array, Stack, Queue,
Linked List
IMPORTANCE OF DATA
STRUCTURES
 Essential in creating fast and powerful
algorithms

 Assist in organizing and managing data

 Make code cleaner and easier to understand


 Abstract: Existing in thought or as an idea but
not having a physical or concrete existence.

 Abstract Data Type: In computer science, an


abstract data type is a theoretical data type
that is largely defined by the operations and
work on it and the limitations that apply. OR

 An abstract data type is a logical description of


how data is viewed and the operations that can
be performed on it, but how this is done is not
necessarily known to the user.
TYPES OF ABSTRACT DATA TYPES

 Stack
 Queue
 Singly Link List
STACK
 A stack is a Last In, First Out (LIFO) data
structure. This means that with a stack the
last item in is the first item to leave the stack.

 Stack data structure is used in calculations


and to hold return addresses. Using the BACK
and UNDO buttons on web browser or word
processing package are actions done using
stacks ADT.
 STACK UNDERFLOW: An error condition that
occurs when an item is called for from the stack, but
the stack is empty.

 STACK OVERFLOW: An error condition that


occurs when there is no room in the stack for a new
item.
REAL LIFE EXAMPLE OF STACK

 Fresh plates are pushed onto to the top


and popped from the top.
OPERATIONS ON A STACK
 push(item) – adds a new item to the top of the
stack
 pop() – removes and returns the top item from
the stack
 peek() – returns the top item from the stack
but does not remove it
 isEmpty() – tests to see whether the stack is
empty, and returns a Boolean value
 isFull() – tests to see whether the stack is full,
and returns a Boolean value
 size() - Return the number of elements in the
stack
PUSH OPERATION
ALGORITHM FOR PUSH

 Initialization, set top=-1

 Repeat step 3 to 5 until top<Max size-1

 Read, item

 Set top=top+1

 Set stack[top]=item

 Print "stack overflow"


POP OPERATION

Deletion of any item from stack is called pop. An item is


deleted from top of the stack, when you delete any item
from stack top will be decreased by 1.
Algorithm for pop
 Set item=stack[top]
 Set top=top-1
 Print "Item deleted“
 Repeated steps 2 to 4 until top>=0
 Print "Stack under flow"

Вам также может понравиться