Question

If stack is an array that contains the entries in a stack, what is a disadvantage...

If stack is an array that contains the entries in a stack, what is a disadvantage of maintaining the top entry of the stack in stack[0]?

Homework Answers

Answer #1

The array has a definite size so does the stack which is to be implemented. So every time we push an element in the stack it is stored as the first element of stack and if we push any element when the stack size if full it will give us an exception.We have to know the upper bound of growth and allocate memory accordingly.

As you know the stack fill its elements from back so first nth index will fill then n-1th ...... then 1st then 0th index. So stack[0] will only be happen when there are atleast n elements pushed in the stack.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1.A stack implemented with an array has what performance? Select one: a. O(n3) b. O(n log...
1.A stack implemented with an array has what performance? Select one: a. O(n3) b. O(n log n) c. O(n) d. O(n2) 2. A stack uses the first in first out insertion and deletion method. Select one: True False 3. Match the following stack operations with their meaning. object pop(); boolean isEmpty(); push (object); integer size(); object top(); meanings are: - returns the number of elements stored -just removes the last inserted elements - returns the last inserted elements without removing...
Assume you have a stack and a queue implemented using an array of size 4. show...
Assume you have a stack and a queue implemented using an array of size 4. show the content of the array for the stack (then the queue) for the following operations: (for the queue replace push by add and pop by remove; keep in mind that the queue uses a circular array): push(-3), push(-5), push(-9), push(-10), pop(), pop(), push(-13), pop(), push( -15), push(-17).
6. (True/False): The RET instruction pops the top of the stack into the instruction pointer. 8....
6. (True/False): The RET instruction pops the top of the stack into the instruction pointer. 8. (True/False): In protected mode, each procedure call uses a minimum of 4 bytes of stack space. 1. Which instruction pushes all of the 32-bit general-purpose registers on the stack? 20. What values will be written to the array when the following code executes? .data array DWORD 4 DUP(0) .code main PROC mov eax,10 mov esi,0 call proc_1 add esi,4 add eax,10 mov array[esi],eax INVOKE...
Write a method named changeStack that takes in a Stack of Integer objects named stackIn as...
Write a method named changeStack that takes in a Stack of Integer objects named stackIn as a parameter and returns another Stack of Integer objects. The returned Stack contains contents that is the result of switching the top half and the bottom half of the stackIn. But the ordering of integers in each half is NOT changed. In the case of odd-size stackIn, the middle element remains in the same position before and after the switch. This method is OUTSIDE...
The following algorithm adds all the entries in a square n × n array A. Analyze...
The following algorithm adds all the entries in a square n × n array A. Analyze this algorithm where the work unit is the addition operation. sum = 0 for i = 1 to n do for j = 1 to n do sum = sum + A[i, j] end for end for write (“Total of all array elements is”, sum)
Complete following function which receives an array of integers and the length of the array, and...
Complete following function which receives an array of integers and the length of the array, and then returns the sum of all the positive numbers in the array. For example, if an array that is passed to this function contains following numbers: -1, 2, 0, 3, 4, -3, 0, 2, 0, and then the return value of the function should be 11. Will this function be working correctly? Yes or No? int sumPositive(int a[],int length) { int s=0;     for(int...
An array of characters contains a few letters. Write a complete C program that will display...
An array of characters contains a few letters. Write a complete C program that will display the output as shown below. Lets assume the array contains =”abcde”. The program should be able to work with any array size, configurable in the program. Expected output Original array = [ a b c d e] a a b a b c a b c d a b c d e
- implement the Stack ADT using the linked list approach. Use C++ program language #include "StackLinked.h"...
- implement the Stack ADT using the linked list approach. Use C++ program language #include "StackLinked.h" template StackLinked::StackLinked (int maxNumber) { } template StackLinked::StackLinked(const StackLinked& other) { } template StackLinked& StackLinked::operator=(const StackLinked& other) { } template StackLinked::~StackLinked() {    clear(); } template void StackLinked::push(const DataType& newDataItem) throw (logic_error) {    } template DataType StackLinked::pop() throw (logic_error) { } template void StackLinked::clear() {    StackNode* t;    while ( top != NULL)    {        t = top;       ...
For the AVR Microcontroller What is Stack? What is Stack Pointer? Explain their use and advantages...
For the AVR Microcontroller What is Stack? What is Stack Pointer? Explain their use and advantages in your own words!
In R create a 5x6x4 array that contains the integers 1 through 120 entered in the...
In R create a 5x6x4 array that contains the integers 1 through 120 entered in the default fashion. Then subset the array to show the second and third row, the first, fourth, and sixth colums and every layer except the first and second.