How is it possible to insert different type of elements in
stack?
Answers were Sorted based on User's Feedback
Answer / poornakala
you ca implement stack with union datatype... u may think
of structures.. but struct use storin of all values and mem
allocated for all in each.. but in union only one at a
time... this is right i think...
Is This Answer Correct ? | 61 Yes | 9 No |
Answer / rabia altaf
we can make stack using class template .. now it can accept
every type of object ..
Is This Answer Correct ? | 19 Yes | 5 No |
Answer / 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 |
Answer / sudipto ghosh
yes it is possible to insert different types of element in a
stack.
insted of defining the member as int or float or so on. we
will define each element as a union which will be consisting
of all types of data type and only one can be used at a
time. in order to determine which type of element is being
pushed or poped we will define a flag with in union which
keeps the track of data type being used.
Is This Answer Correct ? | 11 Yes | 3 No |
Answer / devendra
union is the best option because it allocate only one at a time
Is This Answer Correct ? | 6 Yes | 2 No |
Write a program for reversing the Single Linked List?
How do we search a specific element in an array?
Tell me about the different sorting techniques.
You want to insert a new item in a binary search tree. How would you do it?
Explain the uses of b+ tree.
How do you declare A pointer to array of three chars
Write a program to reverse a single linked list.
What is dynamic array with example?
How to increase stack limit in w3wp.exe?
What is the difference between hashset and hashtable?
Parenthesis are never needed in prefix or postfix expressions. Why?
What are the standard ways in which a graph can be traversed?