Professional Documents
Culture Documents
Data Structures and Algorithms
Data Structures and Algorithms
struct nameOfThisStructureType
{
typeOfFirstMember nameOfFirstMember;
typeOfSecondMember nameOfSecondMember;
typeOfThirdMember nameOfThirdMember;
...
};
Additional variable declarations can subsequently be made for this structure type.
(1) Basic named definition of the structure is effected same as for Alternative 1.
(2) In ADDITION, one or more variables can be declared within the declaration of
the structure type to be of the defined type.
(3) Other variables may also be declared subsequently to be of the same type of
this structure, using the keyword struct together with the tag name and the variable
names.
struct nameOfThisStructureType
{
typeOfFirstMember nameOfFirstMember;
typeOfSecondMember nameOfSecondMember;
typeOfThirdMember nameOfThirdMember;
...
} variable1OfThisStructureType, variable2OfThisStructureType, . . .;
struct nameOfThisStructureType variable3OfThisStructureType,
variable4OfThisStructureType,
...;
NODE
10 20 30 40
10 20 30 40
LINKED LIST
Header L
10 20 30 40
FIND ROUTINE
P = P Next;
return P Next;
Temp,P=NULL
NODE
free (Temp);
}
else
{
Temp = P;
P Blink Flink = P Flink;
free (Temp);
}
}
Polynomial ADT
We can perform the polynomial manipulations such as
addition, subtraction and differentiation etc.
}
return (head1); Prepared by K.Durga Devi /AP 34
}
What is a stack?
• Stores a set of elements in a particular order
• Stack principle: LAST IN FIRST OUT
• = LIFO
• It means: the last element inserted is the first one to be removed
• Example
E top
D top D D
C top C C C
B top B B B B
A top A A A A A
Example : -
Pile of coins., a stack of trays in cafeteria.
Operations On Stack
The fundamental operations performed on a stack are
1. Push
2. Pop
Prepared by K.Durga Devi /AP 38
PUSH :
The process of inserting a new element to the top of the
stack. For every push operation the top is incremented
by 1.
POP :
The process of deleting an element from the top of
stack is called pop operation. After every pop operation
the top pointer is decremented by 1.
OverFlow
Attempt to insert an element when the stack is full is
said to be overflow.
UnderFlow
Attempt to delete an element, when the stack is empty
is said to be underflow.
Array Implementation
In this implementation each stack is associated with a pop
pointer, which is -1 for an empty stack.
• To push an element X onto the stack, Top Pointer is
incremented and then set Stack [Top] = X.
• To pop an element, the stack [Top] value is returned and the
top pointer is decremented.
• pop on an empty stack or push on a full stack will exceed the
array bounds.