Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Does array sort mutate?

814


What is height balanced tree?

929


What is the difference between a Stack and a Queue.

956


Why do we need a data structure?

1000


What are linked lists most commonly used for?

893


Explain the difference between a list and array.

955


What are the operations that can be performed on a stack?

913


Is treemap thread safe?

886


What is link list in data structure?

896


Describe the height term in a tree.

970


Which type of memory allocation is referred for linked list?

1189


Tell me the difference between the character array and a string.

950


How would you swap the Kth node from beginning with Kth node from end in a Linked List.

921


Does hashtable allow null values?

867


what is the difference between dynamic as well as non - dynamic data structures.

951