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

Which is faster arraylist or hashmap?

710


What is unmodifiable list?

686


Which sorting is best in time complexity?

689


Tell me what is quick sort?

700


What are the two traversal strategies used in traversing a graph?

720


Why we use linked list?

679


What is the difference between a Stack and a Queue.

668


What is nsmutablearray?

609


Why null is allowed in hashmap?

620


What stack means?

655


How do you find the size of an arraylist?

565


How does a treemap work?

744


What are the objectives of studying data structures?

861


How would you use bsearch() function to search a name stored in array of pointers to string?

668


What is the difference between static and dynamic data?

642