Implementation of Stack Using Array Source Code
Implementation of Stack Using Array Source Code
Source Code :
#include <stdio.h>
#define SIZE 10
int stack[SIZE];
int top = -1;
int pop()
{
if(top >= 0)
{
int n = stack[top];
top--;
return n;
}
}
int Top()
{
return stack[top];
}
intisempty()
{
return top<0;
}
void display()
{
inti;
for(i=0;i<=top;i++)
{
printf("%d\n",stack[i]);
}
}
int main()
{
push(4);
push(8);
display();
pop();
display();
return 0;
}
void enqueue(int x)
{
if(q.rear == SIZE-1)
{
printf( "\nQueue is full, %d",q.rear);
}
else
{
q.a[++q.rear] = x;
}
}
Int dequeue()
{
if (q.rear==-1 &&q.front==-1)
{
printf(“Queue – Underflow error”);
}
Else
{
printf("\ndequed %d", q.a[q.front]);
returnq.a[++q.front];
}
}
void display()
{
inti;
printf("\n");
for(i = q.front; i<= q.rear; i++)
{
printf("%d\t", q.a[i]);
}
}
void main()
{
q.front=-1;
q.rear=-1;
enqueue(15);
enqueue(100);
enqueue(150);
display();
dequeue();
display();
dequeue();
}