Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to create a stack using array?

0 votes
asked Nov 7, 2020 by npatel300 (1,440 points)

1 Answer

+1 vote
answered Nov 7, 2020 by xDELLx (10,500 points)
Short answer : Allow insertion /deletion only at end of array.

Long Answer : Consider an array of ,initially, 50 elements ,count intially -1.

Push operation : When inserting keep a count of elements present,increment count ,overwrite element present at index count .

Pop operation : If we have a valid count , return element at index count. count--.

Display stack: if count is valid,starting at index count -1 till count =0 ,print all elemenets

Food for thought:

by chance if count >50 ,create new stack & copy paste data from original stack.(but now we need to release original memory ,allocate new memory (but how much 1 element worth mem.2 elements woth memeory 50 ,perhaps ??)

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...