0% found this document useful (0 votes)
101 views2 pages

Hariani Andi Tawakal (BI07210007) Tutorial Data Structure (IT00503) Stack Tutorial

The document discusses stack operations: 1. InitializeStack reinitializes an empty stack, deallocating memory for any existing elements and setting the top pointer to null. 2. Push adds a new element to the top of the stack by creating a new node, storing the element, and updating the top pointer. 3. Pop removes the top element by making the top pointer point to the next element and deleting the current top node. 4. CopyStack makes a copy of a stack passed as a parameter, useful for copy constructors and overloaded assignment operators.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views2 pages

Hariani Andi Tawakal (BI07210007) Tutorial Data Structure (IT00503) Stack Tutorial

The document discusses stack operations: 1. InitializeStack reinitializes an empty stack, deallocating memory for any existing elements and setting the top pointer to null. 2. Push adds a new element to the top of the stack by creating a new node, storing the element, and updating the top pointer. 3. Pop removes the top element by making the top pointer point to the next element and deleting the current top node. 4. CopyStack makes a copy of a stack passed as a parameter, useful for copy constructors and overloaded assignment operators.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Hariani Andi Tawakal (BI07210007) Tutorial Data Structure (IT00503) Stack Tutorial 1. Explain the operation initializeStack.

A stack is a list of homogenous elemets in which of addition and deletion of elements occurs only at one end. it also known as Last In First Out (LIFO) data structure. There are the three operation of stack which is push, top and pop operation. The operation initializeStack reinitializes the stack to the empty spaces. We are using linked implementation of stack because the stack might contain some element, so that it must be deallocate the memory occupied by the stack elements and set stackTop to null. The push operation is that the newElement will be added at the beginning of the linked list pointed to by stackTop. In the case of pop, the node pointed to by stackTop will be removed. In both cases, the value of the pointer stackTop is updated. The operation of top returns the info of the node that stackTop is pointing top.

2. Explain the operation push.

As shown in figure 7-12, to push D into the stack, first we create a new node and store D into it. Next , we put the new node on the top of the stack. Finally, we make stackTop point to the top element of the stack.we do not to check whether the stack is full before we push an element onto the stack because in this implementation, logically the stack is never full. The definition of the function push is as follow:

3. Explain the pop operation.

As shown in figure 7-14, firt we make a pointer temp point to the top of the snack. Next we are make stackTop point to the next element of the stack, which will become the top element of the stack . Finally, the we delete temp. The definition of the function pop is as follow:

4. Explain the function copyStack. The function copyStack makes a copy of a stack. The stack to be copied is passed as a parameter to the function copyStack. To use this function to implement the copy constructor and overload the assignment operator.

You might also like