#include<stdio.h>
#include<conio.h>
#define MAX 10
typedef struct stack
{
int item[MAX];
int Top;
}stk;
void createstack(stk *);
void push(stk *,int);
int pop(stk *);
int isempty(stk *);
int isfull(stk *);
int main()
{
int choice;
int value;
stk s;
createstack(&s);
do{
clrscr();
printf("\n\t Main Menu");
printf("\n1. Push");
printf("\n2. Pop");
printf("\n3. Exit");
printf("\nEnter your choice=");
scanf("%d",choice);
switch(choice)
{
case 1: printf("\nEnter the value to be inserted=");
scanf("%d",value);
push(&s,value);
getch();
break;
case 2: value=pop(&s);
if (value==0)
printf("\n Underflow: Stack is empty");
else
printf("\n Popped Element is %d",value)
getch();
break;
case 3: exit();
defualt: printf("\nInvalid choice");
}
}while(1);
return 0;
}
void createstack(stk *s)
{
s->Top=-1;
}
void push(stk *s,int element)
{
if(isfull(s))
{
printf("\nOverflow: Stack is full");
return;
}
s->Top++;
s->item[s->Top]=element;
printf("\nValue is pushed onto the stack");
}
int pop(stk *)
{
int popped;
if (isempty(s))
return 0;
popped=s->item[s-.Top];
s->Top-;
return popped;
}
int isempty(stk *)
{
return s->Top==-1;
}
int isfull(stk *)
{
return s->Top==MAX-1;
}
Program for Stack implementation through Array
#include <stdio.h>
#include<ctype.h>
# define MAXSIZE 200
int stack[MAXSIZE];
int top; //index pointing to the top of stack
void main()
{
void push(int);
int pop();
int will=1,i,num;
clrscr();
while(will ==1)
{
printf("
MAIN MENU:
1.Add element to stack
2.Delete element from the stack
");
scanf("%d",&will);
switch(will)
{
case 1:
printf("
Enter the data... ");
scanf("%d",&num);
push(num);
break;
case 2: i=pop();
printf("
Value returned from pop function is %d ",i);
break;
default: printf("Invalid Choice . ");
}
printf("
Do you want to do more operations on Stack ( 1 for yes, any other key to exit) ");
scanf("%d" , &will);
} //end of outer while
} //end of main
void push(int y)
{
if(top>MAXSIZE)
{
printf("
STACK FULL
");
return;
}
else
{
top++;
stack[top]=y;
}
}
int pop()
{
int a;
if(top<=0)
{
printf("
STACK EMPTY
");
return 0;
}
else
{
a=stack[top];
top--;
}
return(a);
}
/* Program to implement stacks through arrays */
#include <stdio.h>
#include <conio.h>
int stack[100];
int sz,top=-1,n;
void push()
{
top++;
if(top>=sz)
{
printf("\nStack full");
return;
}
else
{
printf("\nEnter element to be pushed:");
scanf("%d",&n);
stack[top]=n;
printf("\n%d pushed onto stack");
}
}
int pop()
{
top--;
if(top<0)
return -1;
else
return stack[top];
}
void main()
{
char ch,op;
clrscr();
printf("\nEnter size of stack:");
scanf("%d",&sz);
do
{
printf("\nEnter (p)ush,p(o)p:");
fflush(stdin);
op=getchar();
switch(op)
{
case 'p':push();break;
case 'o':n=pop();
if(n!=-1)printf("\n%d popped",n);
else printf("\nStack is empty");
break;
default:printf("\nInvalid option");break;
}
printf("\nTo continue,enter y:");
fflush(stdin);
ch=getchar();
}
while(ch=='y')
}
#include<conio.h>
#define MAX 10
typedef struct stack
{
int item[MAX];
int Top;
}stk;
void createstack(stk *);
void push(stk *,int);
int pop(stk *);
int isempty(stk *);
int isfull(stk *);
int main()
{
int choice;
int value;
stk s;
createstack(&s);
do{
clrscr();
printf("\n\t Main Menu");
printf("\n1. Push");
printf("\n2. Pop");
printf("\n3. Exit");
printf("\nEnter your choice=");
scanf("%d",choice);
switch(choice)
{
case 1: printf("\nEnter the value to be inserted=");
scanf("%d",value);
push(&s,value);
getch();
break;
case 2: value=pop(&s);
if (value==0)
printf("\n Underflow: Stack is empty");
else
printf("\n Popped Element is %d",value)
getch();
break;
case 3: exit();
defualt: printf("\nInvalid choice");
}
}while(1);
return 0;
}
void createstack(stk *s)
{
s->Top=-1;
}
void push(stk *s,int element)
{
if(isfull(s))
{
printf("\nOverflow: Stack is full");
return;
}
s->Top++;
s->item[s->Top]=element;
printf("\nValue is pushed onto the stack");
}
int pop(stk *)
{
int popped;
if (isempty(s))
return 0;
popped=s->item[s-.Top];
s->Top-;
return popped;
}
int isempty(stk *)
{
return s->Top==-1;
}
int isfull(stk *)
{
return s->Top==MAX-1;
}
One.
2 stacks required
yes it is, other linear data structures are lists,queues,stacks,arrays
Stacks are often implemented using the same node structure as a linked list.
Four stacks. The boilers used 3 of the stacks for exhaust, the fourth was used to vent Titanics' numerous kitchens and galleys.
One.
2 stacks required
Stacks are primarily used to implement backtracking algorithms.
yes it is, other linear data structures are lists,queues,stacks,arrays
chk out the following link showing you how to implement stack. Though it is a c++ implementation it may still help you. http://thetechnofreaks.com/2011/10/26/4-creating-a-stack/#ixzz1bvp8FXdb
Yes
Stacks are often implemented using the same node structure as a linked list.
193,000,000/100 = 1,930,000 stacks. 193,000,000/100 = 1,930,000 stacks. 193,000,000/100 = 1,930,000 stacks. 193,000,000/100 = 1,930,000 stacks.
granum are stacks of thylakoids. grana are several stacks of thylakoids. :)
That would depend on what type of stacks, or stacks of what objects, the individual is looking for. Long Island University has a comprehensive document online that guides the reader through the organization and uses of library stacks, or the shelves on which books are housed. Cisco offers tutorials on Stack protocol in computer systems. Lyrics for the song Stacks by Bon Iver can be found on YouTube and lyrics sites such as Metro Lyrics. Businesses called Stacks range from bookstores to coin and collectibles outlets to clothing boutiques.
stacks footer
One of the applications that I use a stack for is searching through a file system (or a large/complex tree). stack s; s.push(start_directory); while( !s.empty() ) current = s.pop(); s.pushAll( current.children ); if( s is what we're looking for ) exit(); // otherwise, keep looping