What do you mean by stack program?
Get me an example stack program?

Answer Posted / puneettan

A Stack can be imagined as dinner plates put one over the
another.
'Push' means-- Inserting a new value(like putting a new
dinner plate on the top of the stack)
'Pop' means-- Removing(deleting) a value from the stack(just
like we remove a plate from the top of the stack)

A Stack follows L.I.F.O(Last In First Out).. This means, the
value which was last inserted into a stack would be the
first one to be removed. In the analogous case of dinner
plates, imagine that the plate kept last, on the top of
other plates will have to be removed first. you cannot
remove a plate at the bottom directly.

<--Program, same as given in 1st answer-->
//declaring the variables
char stack[10]
int top=-1;

//making a function for 'Push' mechanism
void push(char d)
{
if(to==9)
printf("stack is full");
else
stack[++top]=d;
}

//making a function for 'Pop' mechanism
char pop()
{
if(top==-1)
return('\0')
else
return(stack[top--]);
}

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can destructor be overloaded?

568


assume the program must insert 4 elements from the key board and then do the following programs.sequential search(search one of the elements),using insertion sort(sort the element) and using selection sort(sort the element).

1641


what is the sylabus for priliminaries?

1651


Why is static class not inherited?

575


Is abstract thinking intelligence?

568






What are different oops concepts?

551


what is graphics

1988


What is inheritance and how many types of inheritance?

594


What is class in oop with example?

592


What does <> mean pseudocode?

595


What is encapsulation c#?

577


what are the different types of qualifier in java?

1813


What is byval and byref? What are differences between them?

1664


#include #include #include #include void insert(struct btreenode **, int); void inorder(struct btreenode *); struct btreenode { struct btreenode *leftchild; struct btreenode *rightchild; int data; }; main() { struct btreenode *bt; bt=(struct btreenode *)NULL; int req,i=1,num; clrscr(); printf("Enter number of nodes"); scanf("%d",&req); while(i<=req) { printf("Enter element"); scanf("%d",&num); insert(&bt,num); i++; } inorder(bt); } void insert(struct btreenode **sr, int num) { if(*sr==NULL) { *sr=(struct btreenode *)malloc (sizeof(struct btreenode)); (*sr)->leftchild=(struct btreenode *)NULL; (*sr)->rightchild=(struct btreenode *)NULL; (*sr)->data=num; return; } else { if(num < (*sr)->data) insert(&(*sr)->leftchild,num); else insert(&(*sr)->rightchild,num); } return; } void inorder(struct btreenode *sr) { if(sr!=(struct btreenode *)NULL) { inorder(sr->leftchild); printf("\n %d",sr->data); inorder(sr->rightchild); } else return; } please Modify the given program and add two methods for post order and pre order traversals.

3217


What is the real time example of inheritance?

610