C and Datastructures programming. How to begin C and Datastructures programming. Steps to be followed.We will see example of Stack.
Firstly Identify the problem.
Secondly ,find out the operations to be performed.
STACK: Ordered collection of homogeneous items is Stack.
1) FILO (First in last out)
2)Grows dynamically at one end while another end is fixed.
Program on Stack
# define Max 100;
struct stack{
int top;
int item[Max] ;
};
main()
{
struct stack s;
}
void push(struct stack *ps,int x)
{
if (ps->top==Max-1)
{
printf("Stack is full");
exit();
}
ps->item[++ps->top]=x;
}
topofstack(struct stack *ps)
return(ps->item[ps->top]);
int empty(struct stack *ps)
{
return(ps->top==-1);
}
int pop(struct stack *ps)
{
int x;
if empty()
{
printf("Stack is empty");
exit();
}
return(ps->item[++ps->top]);
}
No comments:
Post a Comment