Thursday, August 11, 2011

Data Structures (Stack operations using arrays)

#include<stdio.h>
#include<conio.h>

int top = -1;
int stack[10];
void push(int data)
{
stack[++top] = data;
printf("Data pushed\n");
}

void pop()
{
if(top!=-1)
{
printf("\n%d is popped out of the stack",stack[top]);
top--;
}
else
printf("Stack empty");


}

int main()
{
push(10);
push(20);
pop();
getch();
}

No comments:

Post a Comment