Program of stack using array

There are two basic methods for the implementation of stacks--- one where the memory is used statically(by using Array) and the other where the memory is used dynamically(by Linked List).

Array based implementation..

In this scheme, an array of certain maximum size is allocated memory statically(that means once for all,elements are fixed distance apart).

/* Program of stack using array*/

#include<stdio.h>

#define MAX 5

int topp = -1;

int stack_arrr[MAX];

main()

{

                int choicce;

                while(1)

                {

                                printf("Press 1...>Push\n");

                                printf("Press 2...>Pop\n");

                                printf("Press 3...>Display\n");

                                printf("Press 4....Quit\n");

                                printf("Enter your choicce : ");

                                scanf("%d",&choicce);

                                switch(choicce)

                                {

                                 case 1 :

                                                push();

                                                break;

                                 case 2:

                                                pop();

                                                break;

                                 case 3:

                                                display();

                                                break;

                                 case 4:

                                                exit(1);

                                 default:

                                                printf("Sry!Wrong choicce\n");

                                }/*switch End*/

                }/* while End*/

}/*main() End*/

push()

{

                int pushed_iteem;

                if(topp == (MAX-1))

                                printf("Ooo!Stack Overflow\n");

                else

                {

                                printf("Enter the number(pushed element)…….> : ");

                                scanf("%d",&pushed_iteem);

                                topp=topp+1;

                                stack_arrr[topp] = pushed_iteem;

                }

}/*push() End*/

pop()

{

                if(topp == -1)

                                printf("Ooo!Stack Underflow\n");

                else

                {

                                printf("Popped element is : %d\n",stack_arrr[topp]);

                                topp=topp-1;

                }

}/*pop() End*/

display()

{

                int ii;

                if(topp == -1)

                                printf("no elements.....\n");

                else

                {

                                printf("Elements are.....> :\n");

                                for(ii = topp; ii >=0; ii--)

                                                printf("%d\n", stack_arrr[ii] );

                }

}/* display() End*/

Output....

stack using array