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

What is raid (redundant array of inexpensive disks)? Explain its level?

487


How do you do binary search?

497


what is the difference between singly and doubly linked lists?

543


What are the advantages of sorting and filtering data?

502


What is the difference between sorting and classifying?

485






How many null values are allowed in a set?

471


How do you sort an arraylist?

491


What are the complexity of binary search?

455


What is ds tree?

525


Why is hashmap not thread safe?

502


What is the best case complexity of quicksort?

522


Define a tree?

588


Is pointer a variable?

509


What is the difference between for and foreach loop?

463


Calculate the address of a random element present in a 2d array, given base address as ba.

1084