answersLogoWhite

0


Best Answer

You would do this if you implement a stack using an array. Using a zero-based index to keep track of the top of the stack (the end of the array) means we must use the value -1 to indicate an empty stack. This is because an array of n elements will have indices 0 through n-1, where index n-1 represents the element at top of the stack. An empty stack has 0 elements, therefore the top of the stack is represented by index -1.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why you will declare top as -1 for stacks to be empty in c program?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How you stacks object on top of each other?

PowerPoint stacks these objec on top of each other in the other in which they inserted or drawn


What is stacks?

pre stacking and post stacking imaging techingues, its applications


Why do waste stacks have a wire cage on top?

i have no bloody idea


How do you stack 15 books equal in 2 stacks?

seven books in each stack one book open on top of the stacks so it would make both stacks evenly have seven and one-half books


What colors were the titanic smoke stacks?

orange on the bottom black on the top


How do you build the towers in speed stacks?

u stack 2 next to each other and put one on top


'write a simple program for stack operation in c plus plus?

void push(int y) { if(top>stackSize) { cout<<"stack full"<<endl; return; } else { top++; stack[top]=y; } } int pop() { int a; if(top<=0) { cout<<"stack is empty"<<endl; return 0; } else { a=stack[top]; top--; } return(a); }


How do you get the stacks of books out the way on shrink ray island?

You go to the top of the bookshelf and push down the book tess tree.


What floats that is a household item?

A pumice stone. An empty bottle with its top on.


What are the three top rated detox programs listed on the internet?

The top three top rated detox programs listed on the Internet are the hospital or a medical clinic based program, outpatient program and the residential rehab program.


How do you write a pseudocode for basic operation on stack?

Stack operations in pseudo-code:STACK-EMPTY(S)if top[S] = 0return trueelse return falsePUSH(S, x)top[S]


How do you empty cache on safari?

Open Safari, click on the "Safari" button next to the Apple in the top left hand corner of the screen. Click "Empty Cache" and then "Empty" and all your caches will be gone.