Escolar Documentos
Profissional Documentos
Cultura Documentos
# include<stdio.h>
# include<string.h>
# include<ctype.h>
int stack[100];
int data;
}
}
if(top - i + 1 < 0)
{
peeped_element = 0;
flag = 0;
}
else
{
flag = 1;
peeped_element = s[top-i +1];
}
return (peeped_element);
}
/* definition of the display function */
void display(int s[])
{
int i;
if(top == -1)
{
printf("stack is empty");
}
else
{
for(i = top; i>=0; --i)
printf(" %d ", s[i]);
}
}
/* function main */
void main()
{
int data;
char choice;
int q = 0;
int top = -1;
do
{
printf(" \npush->i peep->p quit->q:");
printf("\ninput the choice : ");
do
{
choice = getchar();
choice =tolower(choice);
}while(strchr("ipq",choice)==null);
printf("your choice is: ", choice);
switch(choice)
{
case 'i' :
printf("\n input the element to push:");
scanf("%d", &data);
push(stack, data);
if(flag)
{
printf("\n after inserting ");
display(stack);
if(top == (size-1))
printf("\n stack is full");
}
else
printf("\n stack overflow after pushing");
break;
case 'p' :
data = peep(stack);
if(flag)
{
printf("\n data is peeped: %d", data);
printf("\n stack is as follows:\n");
display(stack);
}
else
printf("\n stack underflow");
break;
case 'q':
q = 1;
}
} while(!q);
}
# include<stdio.h>
# include<string.h>
# include<ctype.h>
/* function main */
void main()
{
int data;
char choice;
int q = 0;
int top = -1;
do
{
printf(" \npush->i pop->p quit->q:");
printf("\ninput the choice : ");
do
{
choice = getchar();
choice =tolower(choice);
}while(strchr("ipq",choice)==null);
printf("your choice is: %c",choice);
switch(choice)
{
case 'i' :
printf("\n input the element to push:");
scanf("%d", &data);
push(stack, data);
if(flag)
{
printf("\n after inserting ");
display(stack);
if(top == (size-1))
printf("\n stack is full");
}
else
printf("\n stack overflow after pushing");
break;
case 'p' :
data = pop(stack);
if(flag)
{
printf("\n data is popped: %d", data);
printf("\n rest data in stack is as follows:\n");
display(stack);
}
else
printf("\n stack underflow" );
break;
case 'q':
q = 1;
}
} while(!q);
}
# include<stdio.h>
# include<string.h>
# include<ctype.h>
int stack[100];
int data;
}
}
if(top - i + 1 < 0)
{
update_element = 0;
flag = 0;
}
else
{
flag = 1;
update_element = s[top-i +1];
printf("\n input the new value: ");
scanf("%d", &s[top-i+1]);
}
return (update_element);
}
void main()
{
int stack[size];
int data;
char choice;
int q = 0;
int top = -1;
do
{
printf(" \npush->i update->u quit->q: ");
printf("\ninput the choice : ");
do
{
fflush(stdin);
choice = getchar();
choice = tolower(choice);
}while(strchr("iuq",choice)==null);
printf("your choice is -> %c", choice);
switch(choice)
{
case 'i' :
printf("\n input the element to pushed: ");
scanf("%d", &data);
push(stack, data);
if(flag)
{
printf("\n after inserting ");
display(stack);
if(top == (size-1))
printf("\n stack is full");
}
else
printf("\n stack overflow after pushing");
break;
case 'u' :
data = update(stack);
if(flag)
{
printf("\n data is peepped: %d", data);
printf("\n stack is as follows:\n");
display(stack);
}
else
printf("\n stack underflow");
break;
case 'q':
q = 1;
}
} while(!q);
}