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

How to sort 1 million floating point numbers?

668


Can constructor be static?

465


Why is data structure used?

528


How would you dynamically allocate a one-dimensional and two-dimensional array of integers?

571


How does a selection sort work for an array?

526






How many passes does bubble sort need?

482


Define an equivalence relation?

644


What is adt example?

542


How can you insert a node in a random location of the linked list?

500


What is the Role of push() and pop() method?

526


How does hashset work internally in java?

507


What’s the difference between enumeration and iterator interfaces?

510


Which interfaces are implemented by printerstatereasons?

512


Which interfaces are implemented by abstractsequentiallist?

510


Explain what is the bucket size, when the overlapping and collision occur at same time?

574