0

Well there is lot of discussion about implementing 3 [ or 2 stacks ] in a single array. but whats the real need or application for implementing stacks like that?

can't we allot memory as 3 seperate stacks [array] itself?. anyway we are alloting array[size * 3] in that single array.

how-to-implement-3-stack-in-a-single-array-efficiently

4
  • in case of storing integers it's easier to use 3 stacks instead of just 1, but when you have a stack of objects, the size of a pointer is much less than the size of an object-clone Commented Jun 5, 2013 at 10:46
  • @KhaledAKhunaifer: I'm a beginner. can you explain elaborately. Commented Jun 5, 2013 at 10:49
  • int is a primitive data type that consume memory space of 4 bytes, an object of class { int, int, int } would consume 3 * 4 = 12 bytes; the size of a pointer in C\C++ is 4 bytes; in the case of integers, we have 4 = 4 so it's not difference .. but in case of objects (as the example) we have 4 < 12 thus it's more efficient to store 3 stacks of the same values using a single one Commented Jun 5, 2013 at 10:53
  • The 3 stacks are the same, but they differ in how items are ordered Commented Jun 5, 2013 at 10:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.