SYBSc (CS) Sem III : Data Structure Slip 17 Que - 2
SAVITIBAI PHULE UNIVERSITY OF PUNE
S. Y. B.Sc. (Computer Science) Semester III
Practical Examination
SUBJECT: CS-233 Practical course based on CS231
/* Q. 2. Write a program that copies the contents of one stack into another. Use stack library to perform basic stack operations. The order of two stacks must be identical. (Hint: Use a temporary stack to preserve the order). */
/// File name : "stack.c"
#include"stack.h"
int init(struct Stack *s)
{
s->top = -1;
}
int isEmpty(struct Stack *s)
{
if(s->top == -1)
{
return 1;
}
else{
return 0;
}
}
int isFull(struct Stack *s)
{
if(s->top == MAX-1)
{
return 1;
}
else{
return 0;
}
}
int Push(struct Stack *s, int n)
{
if(isFull(s) == 1)
{
printf("The stack is overflow...");
return 1;
}
else{
s->top++;
s->data[s->top] = n;
}
return 0;
}
int Pop(struct Stack *s)
{
if(isEmpty(s) == 1)
{
printf("The stack is underflow...");
return 1;
}
else{
return s->data[(s->top)--];
}
}
int Peek(struct Stack *s)
{
if(isEmpty(s) == 1)
{
printf("The stack is underflow...");
return 1;
}
else{
return s->data[s->top];
}
}
Comments
Post a Comment