Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

} Also, can you please explain or show how this would be different if node was u

ID: 3592053 • Letter: #

Question

}

Also, can you please explain or show how this would be different if node was used as an implementation instead of Linked<T> ?

"We don't see the difference between stacks and queues," the Galaxers begin, "since our add0 method for both looks exactly the same" public void add (T item) ensureSpace); array[size] - item; size++ That's because with stacks, you always add to the top, and with queues, to the rear. Since we're using the end of the array to represent both locations, the method will be the same. The difference lies in how they remove items. With a stack, it's always from the same end (the top), with a queue, it's from the opposite end (the front). Let me write the two array-based versions for you...." l/ removing from stack (also known as pop0) public T remove0)

Explanation / Answer

// removing from stack (Pop operation)

Public T remove()

{

    if(size<=-1)

    {

        printf(" Stack is under flow");

    }

    else

    {

        printf(" The popped elements is %d",array[size]);

        size--;

    }

}

// remove from queue – we need two variable size and front in queue operation, the front variable is used to identify top end/front end of the array. From where the deletion operation performed.

Public T remove()

{

    if(front==size)

            {

                printf(" Queue is empty");

            }

            else

            {

                printf(" Deleted Element is %d",array[front++]);

                front++;

            }

}

The Use of node in implementation of stack or queue is very useful because of its dynamic memory allocation and had advantage over array implementation.

The memory is allocated when new item added and memory is released (free) when perform remove/pop operation.