TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Stack Array in Data structure
Sreenath Ks
Jan 05
2016
Code
821
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
Stack array in data structure:
#include<stdio.h>
int
rear=0;
int
front=0;
int
size=5;
main()
{
int
ch;
void
insert();
void
delete();
void
isempty();
void
isfull();
void
showstack();
do
{
//MENU LIST
printf(
"\t===================\n"
);
printf(
"\t 1:insert\n"
);
printf(
"\t 2:delete\n"
);
printf(
"\t 3:isempty\n"
);
printf(
"\t 4:isfull\n"
);
printf(
"\t 5:show stack\n"
);
printf(
"\t 7:stop\n"
);
printf(
"\t===================\n"
);
printf(
"enter your choice\n"
);
scanf(
"%d"
,&ch);
switch
(ch)
{
case
1:
// call insert function and BREAK after that
{
insert();
break
;
}
case
2:
// call delete function and BREAK after that
{
delete();
break
;
}
case
3:
// call isempty function and BREAK after that
{
isempty();
break
;
}
case
4:
// call isfull function and BREAK after that
{
isfull();
break
;
}
case
5:
// call show function and BREAK after that
{
showstack();
break
;
}
case
6:
{
printf(
"program ended\n"
);
break
;
}
default
:
{
printf(
"enter valid choice"
);
break
;
}
}}
// end of do while
while
(ch!=6);
}
//--------------------------------------------------------//
void
insert()
//function to push
{
if
(rear==size)
{
printf(
"stack is full\n"
);
}
else
{
top=top+1;
printf(
"enter the data\n"
);
scanf(
"%d"
,&[top]);
}
}
//-----------------------------------------------------------//
void
pop()
//function to pop
{
if
(top==0)
printf(
"stack is empty"
);
else
{
top=top-1;
}
}
//----------------------------------------------------------//
void
isempty()
//function to isempty
{
if
(top==0)
printf(
"stack is empty"
);
else
{
printf(
"stack is not empty"
);
}
}
//----------------------------------------------------------//
void
isfull()
//function to isfull
{
if
(top==size)
printf(
"stack is full"
);
else
{
printf(
"stack is not full"
);
}
}
//-----------------------------------------------------------//
void
topofstack()
//function to top of stack
{
printf(
"data top of stack=%d\n"
,stack[top]);
}
//------------------------------------------------------------//
void
show()
//function to show
{
int
i;
for
(i=top;i>=0;--i)
{
printf(
"%d\n"
,stack[i]);
}
}
DATA STRUCTURE IN C
C