head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2014.03.29.11.10.17; author emblogic; state Exp;
branches;
next ;
desc
@this is a program of stack implementation using poimters
@
1.1
log
@Initial revision
@
text
@#include”header.h”
int main()
{
void *stack;
int ch,top=-1;
do
{
printf(“1: push\n”);
printf(“2: pop\n”);
printf(“3: display\n”);
printf(“enter your choice\n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
push(&stack,&top);
break;
case 2:
pop(&stack,&top);
break;
case 3:
display(&stack,&top);
break;
defautl:
printf(“wrong choice\n”);
}
}while(ch != 4);
}
@
@#include”header.h”
int push(void **astack,int *atop)
{
static char ch=1;
if( *atop >= MAX-1)
{
printf(“stack overflow\n”);
return -1;
}
if( *atop < 0)
{
*astack=(char *)malloc(1);
(*atop)++;
*(char *)(*astack + *atop)=ch;
ch++;
return 0;
}
(*atop)++;
*astack=(char *)realloc(*astack, (*atop)+1);
*(char *)(*astack + *atop)=ch;
ch++;
return 0;
}
int pop(void **astack,int *atop)
{
if(*atop=0; i–)
{
printf(“the element at loc %d is = %d\n”,i, *(char *)(*astack + i));
}
}
@