123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

   Computer Science / IT
   Electronics
   Electrical
   Mechanical
   Chemical
   Civil

   CAT / MBA

   GMAT / Foreign MBA
Latest Jobs

Engineering Jobs / Technical Jobs
Management Jobs

Sitemap
Terms of use

Displaying  Source Code(s)  
 

 
Implentation of stack using arrays - STACK.C

--------------------------------------------------------------------------------

Description : Implentation of stack using arrays

Code :
/* Implentation of stack using arrays - STACK.C */
# include <stdio.h>
# include <conio.h>
# define SIZE 10
int arr[SIZE], top = -1, i ;
void push() ;
void pop() ;
void display() ;
void main()
{
int ch ;
clrscr() ;
do
{
printf("
[1].PUSH [2].POP [3].Display [4].Exit<BR>) ;
printf("
Enter your choice [1-4] : ") ;
scanf("%d", &ch) ;
switch(ch)
{
case 1 :
push() ;
break ;
case 2 :
pop() ;
break ;
case 3 :
display() ;
break ;
case 4 :
break ;
default :
printf("
Invalid option<BR>) ;
getch() ;
}
} while(ch != 4) ;
getch() ;
}

void push()
{
if(top == SIZE - 1)
{
printf("
Stack is full (overflow)<BR>) ;
getch() ;
return ;
}
top++ ;
printf("
Enter the element to PUSH : ") ;
scanf("%d", &arr[top]) ;
}

void pop()
{
if(top == -1)
{
printf("
Stack is empty (underflow)<BR>) ;
getch() ;
return ;
}
printf("
The POP element is : %d<BR>, arr[top]) ;
getch() ;
top-- ;
}

void display()
{
if(top == -1)
{
printf("
Stack is empty (underflow)<BR>) ;
getch() ;
return ;
}
printf("
The elements in stack are :

TOP") ;
for(i = top ; i >= 0 ; i--)
printf(" -> %d", arr[i]) ;
printf("<BR>) ;
getch() ;
}

 

 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved © copyright 123ENG