How is it possible to insert different type of elements in
stack?

Answer Posted / krishan

We can use a struct containing "void * " in it and an
unsigned int to store the datatype which "void *" will store
(can be set at time of storing the value). To store a value
of any type we can dynamically allocate the space and set
the unsigned int to some pre-determined constants. Like
1 for int type.
2 for char.
3 for char string.
4 for any other type. say some user datatype.

Is This Answer Correct ?    21 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Differentiate between hashmap and treemap.

600


In what areas do data structures applied?

579


Which is better bubble sort or selection sort?

541


Define balancing condition for AVL Tree.

634


What is peek in stack?

553






What is sorting in math?

606


What is the structure of an array?

545


Which sorting is best for large data?

566


How do you do a selection sort?

571


Can we add heterogeneous elements into treemap?

633


Is bubble sort slow?

597


Write any two principles of gradation of structures.

651


Which is the parent class of deque class?

578


What are arrays give example?

577


What is a multidimensional array?

607