Computer Science, asked by ravindras931, 6 months ago

write down the memory representation of stack using array
if u give correct answer i will mark u as brainlist or report Ur answer​

Answers

Answered by raghavvn2008
0

Answer:

There are two main ways: using a one-dimensional array and a single linked list. Array Representation of Stacks: First we have to allocate a memory block of sufficient size to accommodate the full capacity of the stack. ... A single linked list structure is sufficient to represent any stack.

A stack is a data structure that can be represented as an array. Let us learn more about Array representation of a stack –

An array is used to store an ordered list of elements. Using an array for representation of stack is one of the easy techniques to manage the data. But there is a major difference between an array and a stack.

Size of an array is fixed.

While, in a stack, there is no fixed size since the size of stack changed with the number of elements inserted or deleted to and from it.

Despite the difference, an array can be used to represent a stack by taking an array of maximum size; big enough to manage a stack.

For Example:

We are given a stack of elements: 12 , 08 , 21 , 33 , 18 , 40.

Step 1:

Push (40).

Top = 40

Element is inserted at a[5].

Step 2:

Push (18).

Top = 18

Element is inserted at a[4].

Step 3:

Push (33).

Top = 33

Element is inserted at a[3].

Step 4:

Push (21).

Top = 21

Element is inserted at a[2].

Step 5:

Push (08).

Top = 08

Element is inserted at a[1].

Step 6:

Push (12).

Top = 12

Element is inserted at a[0].

Step 7:

Top = -1.

End of array NOW it's complete

Similar questions