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

Answers were Sorted based on User's Feedback



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

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

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

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

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

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

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

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

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

Answer / devendra

union is the best option because it allocate only one at a time

Is This Answer Correct ?    6 Yes 2 No

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

Answer / touchriverian

guess that union is the best option.

Is This Answer Correct ?    6 Yes 3 No

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

Answer / alex

using void

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More Data Structures Interview Questions

Define a Deque?

0 Answers  


What is linear-logarithm chasm?

0 Answers  


What member function places a new node at the end of the linked list?

0 Answers  


What are the advantages of linked list over an array?

0 Answers  


What is the difference between list and arraylist?

0 Answers  






Can we add duplicate keys in a hashmap?

0 Answers  


How do I sort a hashmap key?

0 Answers  


What is Jagged Arrays?

0 Answers  


Explain the types of linked lists.

0 Answers  


1) Program A and B are analyzed and found to have worst- case running times no greater than 150nlog2n and n2 respectively.Answer the folloWing questions if possible.. i) which program has the better guarantee on the running time,for larger values of n(n>10000) ? ii) which program has the better guarantee on the running time,for small values of n(n<100) ? iii) which program will run faster on average for n =1000 2) wRite a program to compute the number of collisions required in a long random sequence of insertions using linear probing ,quadratic probing and double hashing 3) what is the optimal way to compute A1 A2 A3 A4 A5 A6 where the dimensions of the matrices are A1:10*20 A2 : 20 * 1 A3 : 1 * 40 A4 : 40*5 A5 : 5 * 30 A6 : 30 X 15

5 Answers   KPIT,


Explain merge sort algorithms.

0 Answers  


What is complete binary tree in data structure?

0 Answers  


Categories